# -*- coding: utf-8 -*-
from __future__ import division

__author__ = 'Administrator'
from PyQt4 import QtGui, QtCore
import sys
import os
from canard import can
from canard.hw import cantact
import locale
import time
import re
import datetime
import random
import serial
import binascii

from ui import Ui_MainWindow


class MyWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        # 打开端口
        self.connect(self.ui.ButtonOpen, QtCore.SIGNAL("clicked()"), self.OpenPort)
        # 调试区发送
        self.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.SendMessage)
        # 清除发送信息
        self.connect(self.ui.pushButton_5, QtCore.SIGNAL("clicked()"), self.ClearSendMessage)
        self.connect(self.ui.pushButton_6, QtCore.SIGNAL("clicked()"), self.StopMessage)
        self.connect(self.ui.pushButton_2, QtCore.SIGNAL("clicked()"), self.LoadMessage)
        self.connect(self.ui.pushButton_7, QtCore.SIGNAL("clicked()"), self.LoadSub)
        self.connect(self.ui.pushButton_17, QtCore.SIGNAL("clicked()"), self.NavLoadSub)
        self.connect(self.ui.pushButton_4, QtCore.SIGNAL("clicked()"), self.FTSend)
        self.connect(self.ui.pushButton_14, QtCore.SIGNAL("clicked()"), self.NavSend)
        self.connect(self.ui.pushButton_3, QtCore.SIGNAL("clicked()"), self.ModelSend)
        # 清楚接收信息
        self.connect(self.ui.pushButton_8, QtCore.SIGNAL("clicked()"), self.ClearRecvMessage)
        self.connect(self.ui.pushButton_9, QtCore.SIGNAL("clicked()"), self.UnSupportDSC)
        self.connect(self.ui.pushButton_13, QtCore.SIGNAL("clicked()"), self.SupportSer)
        self.connect(self.ui.pushButton_15, QtCore.SIGNAL("clicked()"), self.UnSupportSer)
        self.connect(self.ui.pushButton_10, QtCore.SIGNAL("clicked()"), self.SendSupportSer)
        self.connect(self.ui.pushButton_11, QtCore.SIGNAL("clicked()"), self.SendSupportSerNot)
        self.connect(self.ui.pushButton_12, QtCore.SIGNAL("clicked()"), self.SendUnSupportSer)
        self.connect(self.ui.pushButton_16, QtCore.SIGNAL("clicked()"), self.ClearLog)
        # self.connect(self.ui.ButtonOpen_2, QtCore.SIGNAL("clicked()"),self.OpenSerial)
        self.connect(self.ui.pushButton_18, QtCore.SIGNAL("clicked()"), self.ExceptAction)
        self.connect(self.ui.pushButton_19, QtCore.SIGNAL("clicked()"), self.ARMonkey)
        self.connect(self.ui.pushButton_20, QtCore.SIGNAL("clicked()"), self.MonkeyTest)

    def OpenPort(self):
        global dev, flag
        pe_on = QtGui.QPalette()
        pe_on.setColor(QtGui.QPalette.Window, QtCore.Qt.green)
        pe_off = QtGui.QPalette()
        pe_off.setColor(QtGui.QPalette.Window, QtCore.Qt.red)
        self.ui.label_28.setAutoFillBackground(True)
        # self.ui.label_38.setAutoFillBackground(True)
        port = str(self.ui.COMPort.toPlainText())
        bitrate = int(self.ui.comboBox_2.currentText())
        if len(port):
            port = "COM" + port
        else:
            port = str(self.ui.comboBox.currentText())
        try:
            dev = cantact.CantactDev(port)
            dev.set_bitrate(bitrate * 1000)
            self.ui.label_28.setPalette(pe_on)
        except:
            self.ui.label_28.setPalette(pe_off)
            QtGui.QMessageBox.information(self, "Information", self.tr("port open failed.pls check it again!"))

    def ExceptAction(self):
        pe_off = QtGui.QPalette()
        pe_off.setColor(QtGui.QPalette.Window, QtCore.Qt.gray)
        self.ui.label_28.setAutoFillBackground(True)
        dev.stop()
        dev.ser.close()
        self.ui.label_28.setPalette(pe_off)

    def SendMessage(self):
        global DataCb, FrameId, SendData0, FrameCount, SendTime, SendData1, SendData2, SendData3, SendData4, SendData5, SendData6, SendData7, SetUPMax
        global VaildByte, LengthByte, MaxValue, setPlus, minValue
        DataCb = int(self.ui.checkBox_2.checkState())
        SetUPMax = int(self.ui.checkBox_4.checkState())
        MaxValue = int(self.ui.textEdit_8.toPlainText())
        setPlus = int(self.ui.lineEdit.text())
        minValue = int(self.ui.textEdit_11.toPlainText())
        FrameId = '0x' + str(self.ui.textEdit.toPlainText())
        FrameId = int(FrameId, 16)
        SendData0 = '0x' + str(self.ui.textEdit_2.toPlainText())
        SendData0 = int(SendData0, 16)
        SendData1 = '0x' + str(self.ui.textEdit_12.toPlainText())
        SendData1 = int(SendData1, 16)
        SendData2 = '0x' + str(self.ui.textEdit_13.toPlainText())
        SendData2 = int(SendData2, 16)
        SendData3 = '0x' + str(self.ui.textEdit_14.toPlainText())
        SendData3 = int(SendData3, 16)
        SendData4 = '0x' + str(self.ui.textEdit_15.toPlainText())
        SendData4 = int(SendData4, 16)
        SendData5 = '0x' + str(self.ui.textEdit_16.toPlainText())
        SendData5 = int(SendData5, 16)
        SendData6 = '0x' + str(self.ui.textEdit_17.toPlainText())
        SendData6 = int(SendData6, 16)
        SendData7 = '0x' + str(self.ui.textEdit_18.toPlainText())
        SendData7 = int(SendData7, 16)
        FrameCount = int(self.ui.textEdit_3.toPlainText())
        SendTime = int(self.ui.textEdit_4.toPlainText())
        VaildByte = int(self.ui.comboBox_5.currentText())
        LengthByte = int(self.ui.comboBox_6.currentText())
        self.worker = Send()
        # self.worker._signal.connect(self.SendFlag)
        self.worker.message_signal.connect(self.MessageInformation)
        self.worker.start()

    def SendFlag(self, flag):
        if flag == 0:
            QtGui.QMessageBox.information(self, "Information", self.tr("send message failed!"))

    def ClearLog(self):
        try:
            os.remove('Oplog.txt')
        except:
            pass

    def MessageInformation(self, count, flag, message):
        NewTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        Str_message = str(message)
        New_message = Str_message.split('\t')
        Message_head = str(New_message[1]).rstrip('\n')
        Message_data = str(New_message[2])
        Final_message = Message_head + '    ' + Message_data
        if flag == 0:
            self.ui.textBrowser.append(NewTime + ' ' + Final_message)
        else:
            f = open('Oplog.txt', 'a')
            f.write(NewTime + ' ')
            f.write('Send' + ' ')
            f.write(Final_message)
            f.write('\n')
            self.ui.textBrowser.append(NewTime + ' ' + Final_message)
        if count == 0:
            self.ui.textBrowser.clear()

    def ClearSendMessage(self):
        self.ui.textBrowser.clear()

    def ClearRecvMessage(self):
        self.ui.textBrowser_3.clear()

    def StopMessage(self):
        try:
            if self.worker.isRunning():
                self.worker.terminate()
            if self.loader.isRunning():
                self.loader.terminate()
            if self.sender.isRunning():
                self.sender.terminate()
        except:
            pass

    def LoadMessage(self):
        global filename, LoopCount, LoopTime, LoopDelay, CountFlag, TimeFlag
        filename = str(QtGui.QFileDialog.getOpenFileName(self, 'Open file'))
        LoopCount = int(self.ui.textEdit_5.toPlainText())
        LoopTime = int(self.ui.textEdit_7.toPlainText()) * 60
        LoopDelay = float(self.ui.textEdit_6.toPlainText())
        CountFlag = int(self.ui.checkBox.checkState())
        TimeFlag = int(self.ui.checkBox_3.checkState())
        if len(str(self.ui.textEdit_6.toPlainText())) == 0:
            LoopDelay = 0
        self.ui.textBrowser_5.clear()
        self.loader = SendFile()
        self.loader.MessageFile_signal.connect(self.MessageInformation)
        StartTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        self.ui.textBrowser_5.setPlainText(StartTime)
        self.loader.start()

    def LoadSub(self):
        global FConfig, FunTest
        FConfig = open('FTConfig.txt', 'r')
        FunTest = str(self.ui.comboBox_3.currentText())
        self.ui.comboBox_4.clear()
        self.configer = GetSub()
        self.configer.Sub_signal.connect(self.UpdateSub)
        self.configer.Dtime_signal.connect(self.UpdateTime)
        self.configer.start()

    def NavLoadSub(self):
        global FConfig, FunTest
        FConfig = open('FTConfig.txt', 'r')
        FunTest = str(self.ui.comboBox_16.currentText())
        self.ui.comboBox_15.clear()
        if FunTest == '道路指引':
            self.ui.comboBox_15.addItem(u'自车')
            self.ui.comboBox_15.addItem(u'左转')
            self.ui.comboBox_15.addItem(u'右转')
            self.ui.comboBox_15.addItem(u'左前方')
            self.ui.comboBox_15.addItem(u'右前方')
            self.ui.comboBox_15.addItem(u'左后方')
            self.ui.comboBox_15.addItem(u'右后方')
            self.ui.comboBox_15.addItem(u'左转掉头')
            self.ui.comboBox_15.addItem(u'直行')
            self.ui.comboBox_15.addItem(u'到达途经点')
            self.ui.comboBox_15.addItem(u'进入环岛')
            self.ui.comboBox_15.addItem(u'驶出环岛')
            self.ui.comboBox_15.addItem(u'到达服务区')
            self.ui.comboBox_15.addItem(u'到达收费站')
            self.ui.comboBox_15.addItem(u'到达目的地')
            self.ui.comboBox_15.addItem(u'进入隧道')
            self.ui.comboBox_15.addItem(u'左侧进入环岛')
            self.ui.comboBox_15.addItem(u'左侧驶出环岛')
            self.ui.comboBox_15.addItem(u'右转掉头')
            self.ui.comboBox_15.addItem(u'顺行')
            self.ui.comboBox_15.addItem(u'无效')
            self.ui.comboBox_15.addItem(u'随机')
            self.ui.comboBox_15.addItem(u'倒序')
            self.ui.textBrowser_4.setPlainText('200')
        else:
            self.configer = GetSub()
            self.configer.Sub_signal.connect(self.UpdateNavSub)
            self.configer.Dtime_signal.connect(self.UpdateNavTime)
            self.configer.start()

    def UpdateTime(self, TIME):
        self.ui.textBrowser_2.clear()
        self.ui.textBrowser_2.setPlainText(TIME)

    def UpdateNavTime(self, TIME):
        self.ui.textBrowser_4.clear()
        self.ui.textBrowser_4.setPlainText(TIME)

    def UpdateSub(self, Sub):
        sub = str(Sub)
        self.ui.comboBox_4.addItem(sub)

    def UpdateNavSub(self, Sub):
        sub = str(Sub)
        self.ui.comboBox_15.addItem(sub)

    def FTSend(self):
        global FItem, FSub, SendTimer, FTname
        # 按照相对路径读取本地文件
        FTname = open('FTConfig.txt', 'r')
        # 选择按照时间发送
        FItem = str(self.ui.comboBox_3.currentText())
        FSub = str(self.ui.comboBox_4.currentText())
        SendTimer = int(self.ui.textBrowser_2.toPlainText())
        self.sender = FTSend()
        self.sender.FTFile_signal.connect(self.MessageInformation)
        self.sender.Bar_signal.connect(self.SendProgress)
        self.sender.start()

    def SendProgress(self, bar):
        self.ui.progressBar.setProperty("value", bar)

    def BadMonkeyCounter(self, count):
        self.ui.textBrowser_6.setPlainText(str(count))

    def MonkeyCounter(self, count):
        self.ui.textBrowser_7.setPlainText(str(count))

    def ARMCount(self, count):
        self.ui.textBrowser_8.setPlainText(str(count))

    def ARMType(self, count):
        self.ui.textBrowser.append(count)

    def TestCount(self, count):
        self.ui.textBrowser_9.setPlainText(count)

    def NavSend(self):
        global FItem, FSub, SendTimer, FTname
        FTname = open('FTConfig.txt', 'r')
        FItem = str(self.ui.comboBox_16.currentText())
        FSub = str(self.ui.comboBox_15.currentText())
        SendTimer = int(self.ui.textBrowser_4.toPlainText())
        self.Nsender = FTSend()
        self.Nsender.FTFile_signal.connect(self.MessageInformation)
        self.Nsender.start()

    def ModelSend(self):
        global DUT_Model, PyAddress, FunAddress, CanID
        self.ui.comboBox_7.clear()
        self.ui.comboBox_9.clear()
        self.ui.comboBox_11.clear()
        self.ui.comboBox_12.clear()
        self.ui.comboBox_13.clear()
        DUT_Model = str(self.ui.comboBox_8.currentText())
        PyAddress = int(self.ui.checkBox_5.checkState())
        FunAddress = int(self.ui.checkBox_6.checkState())
        StartFlag = 0
        if PyAddress:
            CanID = 0x729
        if FunAddress:
            CanID = 0x7DF
        if PyAddress and FunAddress:
            QtGui.QMessageBox.information(self, "Information", self.tr(u"功能寻址和物理寻址只能2选1！！"))
            StartFlag = 1
        if PyAddress == 0 and FunAddress == 0:
            QtGui.QMessageBox.information(self, "Information", self.tr(u"必须选择一种寻址模式！"))
            StartFlag = 1
        if DUT_Model == "默认":
            self.ui.comboBox_7.addItem(u"电控单元复位")
            self.ui.comboBox_7.addItem(u"诊断设备在线")
            self.ui.comboBox_7.addItem(u"读取数据")
            self.ui.comboBox_7.addItem(u"清除诊断信息")
            self.ui.comboBox_7.addItem(u"读取DTC数量")
            self.ui.comboBox_7.addItem(u"读取DTC")
            self.ui.comboBox_9.addItem(u"安全访问-种子")
            # self.ui.comboBox_9.addItem(u"安全访问-密钥")
            self.ui.comboBox_9.addItem(u"通信控制")
            self.ui.comboBox_9.addItem(u"控制DTC设置")
            self.ui.comboBox_9.addItem(u"写入数据")
        if DUT_Model == "扩展":
            self.ui.comboBox_7.addItem(u"电控单元复位")
            self.ui.comboBox_7.addItem(u"诊断设备在线")
            self.ui.comboBox_7.addItem(u"读取数据")
            self.ui.comboBox_7.addItem(u"清除诊断信息")
            self.ui.comboBox_7.addItem(u"读取DTC数量")
            self.ui.comboBox_7.addItem(u"读取DTC")
            self.ui.comboBox_7.addItem(u"通信控制")
            self.ui.comboBox_7.addItem(u"控制DTC设置")
            if self.ui.checkBox_6.checkState():
                self.ui.comboBox_9.addItem(u"写入数据")
                self.ui.comboBox_9.addItem(u"安全访问-种子")
                # self.ui.comboBox_9.addItem(u"安全访问-密钥")
            else:
                self.ui.comboBox_7.addItem(u"写入数据")
                self.ui.comboBox_7.addItem(u"安全访问-种子")
                # self.ui.comboBox_7.addItem(u"安全访问-密钥")
        if DUT_Model == "编程":
            self.ui.comboBox_7.addItem(u"电控单元复位")

            self.ui.comboBox_7.addItem(u"通信控制")
            self.ui.comboBox_7.addItem(u"诊断设备在线")
            self.ui.comboBox_7.addItem(u"控制DTC设置")
            self.ui.comboBox_7.addItem(u"读取数据")
            if self.ui.checkBox_6.checkState():
                self.ui.comboBox_9.addItem(u"写入数据")
                self.ui.comboBox_9.addItem(u"安全访问-种子")
                # self.ui.comboBox_9.addItem(u"安全访问-密钥")
            else:
                self.ui.comboBox_7.addItem(u"写入数据")
                self.ui.comboBox_7.addItem(u"安全访问-种子")
                # self.ui.comboBox_7.addItem(u"安全访问-密钥")
            self.ui.comboBox_9.addItem(u"清除诊断信息")
            self.ui.comboBox_9.addItem(u"读取DTC数量")
            self.ui.comboBox_9.addItem(u"读取DTC")
        if StartFlag == 0:
            self.Modeler = Model()
            self.Modeler.Model_signal.connect(self.MessageInformation)
            self.Modeler.ResponseResult.connect(self.ResponseInformation)
            self.Modeler.RecMessage.connect(self.RecvInformation)
            self.Modeler.RecResult.connect(self.ResultInformation)
            self.Modeler.ModelResult.connect(self.ModelInformation)
            self.Modeler.TimeSignal.connect(self.TimeMessage)
            self.Modeler.Show_signal.connect(self.ShowMessage)
            self.Modeler.start()
        else:
            pass

    def UpdateService(self, Service, UnService):
        Support = str(Service)
        UnSupport = str(UnService)
        self.ui.comboBox_7.addItem(Support)
        self.ui.comboBox_9.addItem(UnSupport)

    def ResponseInformation(self, result):
        if result == 0:
            QtGui.QMessageBox.information(self, "Information", self.tr(u"设备无响应!"))

    def ResultInformation(self, result):
        if result == 0:
            QtGui.QMessageBox.information(self, "Information", self.tr(u"设备响应ID错误！"))
        if result == 1:
            QtGui.QMessageBox.information(self, "Information", self.tr(u"设备响应数据段有错误！"))
        if result == 2:
            QtGui.QMessageBox.information(self, "Information", self.tr(u"设备响应正确！"))

    def RecvInformation(self, message):
        NewTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        f = open('Oplog.txt', 'a')
        f.write(NewTime + ' ')
        f.write('Recv' + ' ')
        self.ui.textBrowser_3.append(message)
        f.write(message)
        f.write('\n')
        f.close()

    def ModelInformation(self, select):
        pe_on = QtGui.QPalette()
        pe_on.setColor(QtGui.QPalette.Window, QtCore.Qt.green)
        pe_off = QtGui.QPalette()
        pe_off.setColor(QtGui.QPalette.Window, QtCore.Qt.white)
        self.ui.label_38.setAutoFillBackground(True)
        self.ui.label_39.setAutoFillBackground(True)
        self.ui.label_40.setAutoFillBackground(True)
        if select == 1:
            self.ui.label_38.setPalette(pe_on)
            self.ui.label_40.setPalette(pe_off)
            self.ui.label_39.setPalette(pe_off)
            self.ui.comboBox_8.clear()
            self.ui.comboBox_8.addItem(u'默认')
            self.ui.comboBox_8.addItem(u'扩展')
            self.ui.comboBox_8.addItem(u'编程')
            self.ui.comboBox_7.clear()
            self.ui.comboBox_7.addItem(u'电控单元复位')
            self.ui.comboBox_7.addItem(u'诊断设备在线')
            self.ui.comboBox_7.addItem(u'读取数据')
            self.ui.comboBox_7.addItem(u'清除诊断信息')
            self.ui.comboBox_7.addItem(u'读取DTC数量')
            self.ui.comboBox_7.addItem(u'读取DTC')
            self.ui.comboBox_9.clear()
            self.ui.comboBox_9.addItem(u'安全访问-种子')
            # self.ui.comboBox_9.addItem(u'安全访问-密钥')
            self.ui.comboBox_9.addItem(u'通信控制')
            self.ui.comboBox_9.addItem(u'控制DTC设置')
            self.ui.comboBox_9.addItem(u'写入数据')
        if select == 2:
            self.ui.label_38.setPalette(pe_off)
            self.ui.label_40.setPalette(pe_on)
            self.ui.label_39.setPalette(pe_off)
        if select == 3:
            self.ui.label_38.setPalette(pe_off)
            self.ui.label_40.setPalette(pe_off)
            self.ui.label_39.setPalette(pe_on)

    def TimeMessage(self, message):
        self.ui.textBrowser.append(message)

    def ShowMessage(self, message):
        self.ui.textBrowser.append(message)

    def UnSupportDSC(self):
        global SubUnSpportDSC
        SubUnSpportDSC = str(self.ui.comboBox_10.currentText())
        self.UnDSCSender = DSCSender()
        self.UnDSCSender.DSCSender_signal.connect(self.MessageInformation)
        self.UnDSCSender.DSCRecv_signal.connect(self.RecvInformation)
        self.UnDSCSender.DSCResult_signal.connect(self.ResultInformation)
        self.UnDSCSender.TimeSignal.connect(self.TimeMessage)

        self.UnDSCSender.start()

    def SupportSer(self):
        self.ui.comboBox_11.clear()
        self.ui.comboBox_12.clear()
        SSer = str(self.ui.comboBox_7.currentText())
        if SSer == "电控单元复位":
            # self.ui.comboBox_11.addItem(u'硬件复位')
            # self.ui.comboBox_11.addItem(u'钥匙开关复位')
            self.ui.comboBox_11.addItem(u'软件复位')
            self.ui.comboBox_12.addItem(u'子功能不支持')
            self.ui.comboBox_12.addItem(u'报文长度错误')
            self.ui.textEdit_9.close()
            # self.ui.comboBox_12.addItem(u'条件未满足')
            # self.ui.comboBox_12.addItem(u'安全访问拒绝')
        if SSer == "诊断设备在线":
            self.ui.comboBox_11.addItem(u'诊断')
            self.ui.comboBox_12.addItem(u'子功能不支持')
            self.ui.comboBox_12.addItem(u'报文长度错误')
            self.ui.textEdit_9.close()
        if SSer == "读取数据":
            self.ui.comboBox_11.addItem(u'零件号')
            self.ui.comboBox_11.addItem(u'供应商名称')
            self.ui.comboBox_11.addItem(u'ECU名称')
            self.ui.comboBox_11.addItem(u'硬件版本号')
            self.ui.comboBox_11.addItem(u'软件版本号')
            self.ui.comboBox_11.addItem(u'ECU流水编号')
            self.ui.comboBox_11.addItem(u'车辆识别号')
            self.ui.comboBox_12.addItem(u'报文长度错误')
            # self.ui.comboBox_12.addItem(u'条件未满足')
            self.ui.comboBox_12.addItem(u'请求超出范围')
            self.ui.textEdit_9.close()
            # self.ui.comboBox_12.addItem(u'安全访问拒绝')
        if SSer == "清除诊断信息":
            self.ui.comboBox_11.addItem(u'HUD系统')
            self.ui.comboBox_11.addItem(u'所有组（所有DTC）')
            self.ui.comboBox_12.addItem(u'报文长度错误')
            self.ui.comboBox_12.addItem(u'请求超出范围')
            self.ui.textEdit_9.close()
        if SSer == "读取DTC数量":
            self.ui.comboBox_11.addItem(u'报告DTC数量')
            self.ui.comboBox_12.addItem(u'子功能不支持')
            self.ui.comboBox_12.addItem(u'报文长度错误')
            self.ui.comboBox_12.addItem(u'请求超出范围')
            self.ui.textEdit_9.close()
        if SSer == "读取DTC":
            self.ui.comboBox_11.addItem(u'报告DTC')
            self.ui.comboBox_12.addItem(u'子功能不支持')
            self.ui.comboBox_12.addItem(u'报文长度错误')
            self.ui.comboBox_12.addItem(u'请求超出范围')
            self.ui.textEdit_9.close()
        if SSer == "安全访问-种子":
            self.ui.comboBox_11.addItem(u'请求级别1种子')
            self.ui.comboBox_11.addItem(u'请求级别2种子')
            self.ui.comboBox_12.addItem(u'子功能不支持')
            self.ui.comboBox_12.addItem(u'报文长度错误')
            self.ui.textEdit_9.close()
        # if SSer == "安全访问-密钥":
        #     self.ui.comboBox_11.addItem(u'请求级别1密钥')
        #     self.ui.comboBox_11.addItem(u'请求级别2密钥')
        #     self.ui.comboBox_12.addItem(u'子功能不支持')
        #     self.ui.comboBox_12.addItem(u'报文长度错误')
        #     self.ui.comboBox_12.addItem(u'请求序列错误')
        #     self.ui.comboBox_12.addItem(u'密钥无效')
        #     self.ui.comboBox_12.addItem(u'超出密钥访问次数限制')
            self.ui.textEdit_9.close()
        if SSer == "通信控制":
            self.ui.comboBox_11.addItem(u'使能接收和发送')
            self.ui.comboBox_11.addItem(u'使能接收且禁止发送')
            self.ui.comboBox_11.addItem(u'禁止接收且使能发送')
            self.ui.comboBox_11.addItem(u'禁止接收且禁止发送')
            self.ui.comboBox_12.addItem(u'子功能不支持')
            self.ui.comboBox_12.addItem(u'报文长度错误')
            self.ui.comboBox_12.addItem(u'请求超出范围')
            self.ui.textEdit_9.close()
        if SSer == "控制DTC设置":
            self.ui.comboBox_11.addItem(u'打开')
            self.ui.comboBox_11.addItem(u'关闭')
            self.ui.comboBox_12.addItem(u'子功能不支持')
            self.ui.comboBox_12.addItem(u'报文长度错误')
            self.ui.textEdit_9.close()
        if SSer == "写入数据":
            self.ui.comboBox_11.addItem(u'零件号')
            self.ui.comboBox_11.addItem(u'供应商名称')
            self.ui.comboBox_11.addItem(u'ECU名称')
            self.ui.comboBox_11.addItem(u'硬件版本号')
            self.ui.comboBox_11.addItem(u'软件版本号')
            self.ui.comboBox_11.addItem(u'ECU流水编号')
            self.ui.comboBox_11.addItem(u'车辆识别号')
            # self.ui.comboBox_12.addItem(u'报文长度错误')
            # self.ui.comboBox_12.addItem(u'条件不满足')
            self.ui.comboBox_12.addItem(u'请求超出范围')
            self.ui.comboBox_12.addItem(u'安全访问拒绝')
            # self.ui.comboBox_12.addItem(u'一般编程错误')
            self.ui.textEdit_9.show()

    def UnSupportSer(self):
        self.ui.comboBox_13.clear()
        SSer = str(self.ui.comboBox_9.currentText())
        if SSer == "电控单元复位":
            self.ui.comboBox_13.addItem(u'条件未满足')
        if SSer == "诊断设备在线":
            self.ui.comboBox_13.addItem(u'诊断')
        if SSer == "读取数据":
            self.ui.comboBox_13.addItem(u'条件未满足')
        if SSer == "清除诊断信息":
            self.ui.comboBox_13.addItem(u'条件未满足')
        if SSer == "读取DTC数量":
            self.ui.comboBox_13.addItem(u'条件未满足')
        if SSer == "读取DTC":
            self.ui.comboBox_13.addItem(u'条件未满足')
        if SSer == "安全访问-种子":
            self.ui.comboBox_13.addItem(u'条件未满足')
        # if SSer == "安全访问-密钥":
        #     self.ui.comboBox_13.addItem(u'条件未满足')
        if SSer == "通信控制":
            self.ui.comboBox_13.addItem(u'条件未满足')
        if SSer == "控制DTC设置":
            self.ui.comboBox_13.addItem(u'条件未满足')
        if SSer == "写入数据":
            self.ui.comboBox_13.addItem(u'安全访问拒绝')
            self.ui.comboBox_13.addItem(u'条件未满足')

    def SendSupportSer(self):
        global Ser, Response, InputMessage
        Ser = str(self.ui.comboBox_7.currentText())
        Response = str(self.ui.comboBox_11.currentText())
        InputMessage = str(self.ui.textEdit_9.toPlainText())
        InLen = len(InputMessage)
        if InLen > 18:
            QtGui.QMessageBox.information(self, "Information", self.tr(u"请不要输入长度大于18的编码！"))
        else:
            self.Sender1 = Send1()
            self.Sender1.Sender1_signal.connect(self.MessageInformation)
            self.Sender1.ResponseResult.connect(self.ResponseInformation)
            self.Sender1.Recv_signal.connect(self.RecvInformation)
            self.Sender1.Result_signal.connect(self.ResultInformation)
            self.Sender1.Model_signal.connect(self.ModelInformation)
            self.Sender1.TimeSignal.connect(self.TimeMessage)
            self.Sender1.start()

    def SendSupportSerNot(self):
        global UnSer, UnResponse
        UnSer = str(self.ui.comboBox_7.currentText())
        UnResponse = str(self.ui.comboBox_12.currentText())
        self.Sender2 = Send2()
        self.Sender2.Sender2_signal.connect(self.MessageInformation)
        self.Sender2.ResponseResult.connect(self.ResponseInformation)
        self.Sender2.Recv_signal.connect(self.RecvInformation)
        self.Sender2.Result_signal.connect(self.ResultInformation)
        self.Sender2.TimeSignal.connect(self.TimeMessage)
        self.Sender2.start()

    def SendUnSupportSer(self):
        global UnSpSer, UnSpResponse
        UnSpSer = str(self.ui.comboBox_9.currentText())
        UnSpResponse = str(self.ui.comboBox_13.currentText())
        self.Sender3 = Send3()
        self.Sender3.Sender3_signal.connect(self.MessageInformation)
        self.Sender3.ResponseResult.connect(self.ResponseInformation)
        self.Sender3.Recv_signal.connect(self.RecvInformation)
        self.Sender3.Result_signal.connect(self.ResultInformation)
        self.Sender3.TimeSignal.connect(self.TimeMessage)
        self.Sender3.start()

    def MonkeyTest(self):
        global MonkeyCount
        MonkeyCount = int(self.ui.textEdit_10.toPlainText())
        self.ui.textBrowser_6.clear()
        self.ui.textBrowser_7.clear()
        self.MonkeyTester = Monkey()
        self.MonkeyTester.Sender_signal.connect(self.MessageInformation)
        self.MonkeyTester.Recv_signal.connect(self.RecvInformation)
        self.MonkeyTester.Monkey_signal.connect(self.MonkeyCounter)
        self.MonkeyTester.BadMonkey_signal.connect(self.BadMonkeyCounter)
        self.MonkeyTester.start()

    def ARMonkey(self):
        self.ui.textBrowser_8.clear()
        self.Monkey = ARMonkey()
        self.Monkey.Sender_signal.connect(self.MessageInformation)
        self.Monkey.ARMCount.connect(self.ARMCount)
        self.Monkey.ARMType.connect(self.ARMType)
        self.Monkey.start()


class Send(QtCore.QThread):
    _signal = QtCore.pyqtSignal(int)
    message_signal = QtCore.pyqtSignal(int, int, str)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        frame = can.Frame(FrameId)
        frame.dlc = 8
        STime = float((SendTime - 2) / 1000)
        count = 1
        flag = 1
        if DataCb:
            if VaildByte == 0:
                if LengthByte == 8:
                    if SetUPMax:
                        Max = MaxValue
                    else:
                        Max = 256
                    for data0 in range(0, Max, setPlus):
                        dev.start()
                        frame.data = [data0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                        self.message_signal.emit(count, flag, str(frame))
                        dev.send(frame)
                        time.sleep(STime)
                        count += 1
            if VaildByte == 1:
                if LengthByte == 8:
                    if SetUPMax:
                        Max = MaxValue
                    else:
                        Max = 256
                    for data1 in range(0, Max, setPlus):
                        dev.start()
                        frame.data = [0x00, data1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                        self.message_signal.emit(count, flag, str(frame))
                        dev.send(frame)
                        time.sleep(STime)
                        count += 1
                if LengthByte == 16:
                    for data2 in range(0, 256):
                        for data1 in range(0, 256, setPlus):
                            if SetUPMax:
                                if count <= MaxValue - minValue:
                                    dev.start()
                                    frame.data = [data2, data1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                    self.message_signal.emit(count, flag, str(frame))
                                    dev.send(frame)
                                    time.sleep(STime)
                                    count += 1
                                else:
                                    break
                            else:
                                dev.start()
                                frame.data = [data2, data1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                self.message_signal.emit(count, flag, str(frame))
                                dev.send(frame)
                                # dev.stop()
                                time.sleep(STime)
                                count += 1

            if VaildByte == 2:
                if LengthByte == 8:
                    for data2 in range(0, MaxValue, setPlus):
                        dev.start()
                        frame.data = [0x00, 0x00, data2, 0x00, 0x00, 0x00, 0x00, 0x00]
                        self.message_signal.emit(count, flag, str(frame))
                        dev.send(frame)
                        # dev.stop()
                        time.sleep(STime)
                        count += 1
                if LengthByte == 16:
                    for data3 in range(0, 256):
                        for data2 in range(0, 256, setPlus):
                            if SetUPMax:
                                if count <= MaxValue - minValue:
                                    dev.start()
                                    frame.data = [0x00, data3, data2, 0x00, 0x00, 0x00, 0x00, 0x00]
                                    self.message_signal.emit(count, flag, str(frame))
                                    dev.send(frame)
                                    # dev.stop()
                                    time.sleep(STime)
                                    count += 1
                                else:
                                    break
                            else:
                                dev.start()
                                frame.data = [0x00, data3, data2, 0x00, 0x00, 0x00, 0x00, 0x00]
                                self.message_signal.emit(count, flag, str(frame))
                                dev.send(frame)
                                # dev.stop()
                                time.sleep(STime)
                                count += 1
            if VaildByte == 3:
                if LengthByte == 8:
                    for data3 in range(0, MaxValue, setPlus):
                        dev.start()
                        frame.data = [0x00, 0x00, 0x00, data3, 0x00, 0x00, 0x00, 0x00]
                        self.message_signal.emit(count, flag, str(frame))
                        dev.send(frame)
                        # dev.stop()
                        time.sleep(STime)
                        count += 1
                if LengthByte == 16:
                    for data4 in range(0, 256):
                        for data3 in range(0, 256, setPlus):
                            if SetUPMax:
                                if count <= MaxValue - minValue:
                                    dev.start()
                                    frame.data = [0x00, 0x00, data4, data3, 0x00, 0x00, 0x00, 0x00]
                                    self.message_signal.emit(count, flag, str(frame))
                                    dev.send(frame)
                                    # dev.stop()
                                    time.sleep(STime)
                                    count += 1
                                else:
                                    break
                            else:
                                dev.start()
                                frame.data = [0x00, 0x00, data4, data3, 0x00, 0x00, 0x00, 0x00]
                                self.message_signal.emit(count, flag, str(frame))
                                dev.send(frame)
                                # dev.stop()
                                time.sleep(STime)
                                count += 1
            if VaildByte == 4:
                if LengthByte == 8:
                    for data4 in range(0, MaxValue, setPlus):
                        dev.start()
                        frame.data = [0x00, 0x00, 0x00, 0x00, data4, 0x00, 0x00, 0x00]
                        self.message_signal.emit(count, flag, str(frame))
                        dev.send(frame)
                        # dev.stop()
                        time.sleep(STime)
                        count += 1
                if LengthByte == 16:
                    for data5 in range(0, 256):
                        for data4 in range(0, 256, setPlus):
                            if SetUPMax:
                                if count <= MaxValue - minValue:
                                    dev.start()
                                    frame.data = [0x00, 0x00, 0x00, data5, data4, 0x00, 0x00, 0x00]
                                    self.message_signal.emit(count, flag, str(frame))
                                    dev.send(frame)
                                    # dev.stop()
                                    time.sleep(STime)
                                    count += 1
                                else:
                                    break
                            else:
                                dev.start()
                                frame.data = [0x00, 0x00, 0x00, data5, data4, 0x00, 0x00, 0x00]
                                self.message_signal.emit(count, flag, str(frame))
                                dev.send(frame)
                                # dev.stop()
                                time.sleep(STime)
                                count += 1
            if VaildByte == 5:
                if LengthByte == 8:
                    for data5 in range(0, MaxValue, setPlus):
                        dev.start()
                        frame.data = [0x00, 0x00, 0x00, 0x00, 0x00, data5, 0x00, 0x00]
                        self.message_signal.emit(count, flag, str(frame))
                        dev.send(frame)
                        # dev.stop()
                        time.sleep(STime)
                        count += 1
                if LengthByte == 16:
                    for data6 in range(0, 256):
                        for data5 in range(0, 256, setPlus):
                            if SetUPMax:
                                if count <= MaxValue - minValue:
                                    dev.start()
                                    frame.data = [0x00, 0x00, 0x00, 0x00, data6, data5, 0x00, 0x00]
                                    self.message_signal.emit(count, flag, str(frame))
                                    dev.send(frame)
                                    # dev.stop()
                                    time.sleep(STime)
                                    count += 1
                                else:
                                    break
                            else:
                                dev.start()
                                frame.data = [0x00, 0x00, 0x00, 0x00, data6, data5, 0x00, 0x00]
                                self.message_signal.emit(count, flag, str(frame))
                                dev.send(frame)
                                # dev.stop()
                                time.sleep(STime)
                                count += 1
            if VaildByte == 6:
                if LengthByte == 8:
                    for data6 in range(0, MaxValue, setPlus):
                        dev.start()
                        frame.data = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, data6, 0x00]
                        self.message_signal.emit(count, flag, str(frame))
                        dev.send(frame)
                        # dev.stop()
                        time.sleep(STime)
                        count += 1
                if LengthByte == 16:
                    for data7 in range(0, 256):
                        for data6 in range(0, 256, setPlus):
                            if SetUPMax:
                                if count <= MaxValue - minValue:
                                    dev.start()
                                    frame.data = [0x00, 0x00, 0x00, 0x00, 0x00, data7, data6, 0x00]
                                    self.message_signal.emit(count, flag, str(frame))
                                    dev.send(frame)
                                    # dev.stop()
                                    time.sleep(STime)
                                    count += 1
                                else:
                                    break
                            else:
                                dev.start()
                                frame.data = [0x00, 0x00, 0x00, 0x00, 0x00, data7, data6, 0x00]
                                self.message_signal.emit(count, flag, str(frame))
                                dev.send(frame)
                                # dev.stop()
                                time.sleep(STime)
                                count += 1
            if VaildByte == 7:
                if LengthByte == 8:
                    for data7 in range(0, MaxValue, setPlus):
                        dev.start()
                        frame.data = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, data7]
                        self.message_signal.emit(count, flag, str(frame))
                        dev.send(frame)
                        # dev.stop()
                        time.sleep(STime)
                        count += 1
                if LengthByte == 16:
                    for data8 in range(0, 256):
                        for data7 in range(0, 256, setPlus):
                            if SetUPMax:
                                if count <= MaxValue - minValue:
                                    dev.start()
                                    frame.data = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, data8, data7]
                                    self.message_signal.emit(count, flag, str(frame))
                                    dev.send(frame)
                                    # dev.stop()
                                    time.sleep(STime)
                                    count += 1
                            else:
                                dev.start()
                                frame.data = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, data8, data7]
                                self.message_signal.emit(count, flag, str(frame))
                                dev.send(frame)
                                # dev.stop()
                                time.sleep(STime)
                                count += 1

        else:
            if FrameCount == 1:
                dev.start()
                frame.data = [SendData0, SendData1, SendData2, SendData3, SendData4, SendData5, SendData6, SendData7]
                self.message_signal.emit(count, flag, str(frame))
                dev.send(frame)
                ##dev.stop()
            else:
                RunFlag = 0
                for count in range(0, FrameCount):
                    dev.start()
                    frame.data = [SendData0, SendData1, SendData2, SendData3, SendData4, SendData5, SendData6,
                                  SendData7]
                    self.message_signal.emit(count, flag, str(frame))
                    dev.send(frame)
                    ##dev.stop()
                    time.sleep(STime)
                    RunFlag += 1

        flag = 1
        self._signal.emit(flag)


class SendFile(QtCore.QThread):
    MessageFile_signal = QtCore.pyqtSignal(int, int, str)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        flag = 0
        if LoopDelay < 0.5:
            Stime = float(LoopDelay / 1000)
        else:
            Stime = float(LoopDelay / 1000)
        clear_flag = 1
        dev.start()
        if CountFlag:
            for count in range(0, LoopCount):
                f = open(filename, 'r')
                for line in f:
                    if len(line) >= 5:
                        SuLine = line.split(' ')
                        Id = '0x' + SuLine[0]
                        Id = int(Id, 16)
                        data0 = '0x' + SuLine[1]
                        data0 = int(data0, 16)
                        data1 = '0x' + SuLine[2]
                        data1 = int(data1, 16)
                        data2 = '0x' + SuLine[3]
                        data2 = int(data2, 16)
                        data3 = '0x' + SuLine[4]
                        data3 = int(data3, 16)
                        data4 = '0x' + SuLine[5]
                        data4 = int(data4, 16)
                        data5 = '0x' + SuLine[6]
                        data5 = int(data5, 16)
                        data6 = '0x' + SuLine[7]
                        data6 = int(data6, 16)
                        data7 = '0x' + SuLine[8]
                        data7 = int(data7, 16)
                        frame = can.Frame(Id)
                        frame.dlc = 8
                        frame.data = [data0, data1, data2, data3, data4, data5, data6, data7]
                        self.MessageFile_signal.emit(clear_flag, flag, str(frame))
                        dev.send(frame)
                        time.sleep(Stime)
                        clear_flag += 1
                        if clear_flag >= 6000:
                            clear_flag = 0
                f.close()
        if TimeFlag:
            StartTime = datetime.datetime.now()
            while (1):
                f = open(filename, 'r')
                for line in f:
                    SuLine = line.split(' ')
                    Id = '0x' + SuLine[0]
                    Id = int(Id, 16)
                    data0 = '0x' + SuLine[1]
                    data0 = int(data0, 16)
                    data1 = '0x' + SuLine[2]
                    data1 = int(data1, 16)
                    data2 = '0x' + SuLine[3]
                    data2 = int(data2, 16)
                    data3 = '0x' + SuLine[4]
                    data3 = int(data3, 16)
                    data4 = '0x' + SuLine[5]
                    data4 = int(data4, 16)
                    data5 = '0x' + SuLine[6]
                    data5 = int(data5, 16)
                    data6 = '0x' + SuLine[7]
                    data6 = int(data6, 16)
                    data7 = '0x' + SuLine[8]
                    data7 = int(data7, 16)
                    frame = can.Frame(Id)
                    frame.dlc = 8
                    frame.data = [data0, data1, data2, data3, data4, data5, data6, data7]
                    self.MessageFile_signal.emit(clear_flag, flag, str(frame))
                    dev.send(frame)
                    time.sleep(Stime)
                    clear_flag += 1
                    if clear_flag >= 6000:
                        clear_flag = 0
                f.close()
                CurrentTime = datetime.datetime.now()
                SendTime = (CurrentTime - StartTime).seconds
                if SendTime <= LoopTime:
                    pass
                else:
                    break


class GetSub(QtCore.QThread):
    Dtime_signal = QtCore.pyqtSignal(str)
    Sub_signal = QtCore.pyqtSignal(str)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        flag = 0
        for line in FConfig:
            new = str(line.decode('gb2312'))
            MathFlag = re.match(FunTest, new)
            if MathFlag:
                flag = 1

            if flag == 1 and len(line) >= 4:
                new_line = new.split(' ')
                if FunTest == new_line[0]:
                    self.Dtime_signal.emit(str(new_line[1]).rstrip('\n'))
                else:
                    self.Sub_signal.emit(str(new_line[0]))

            if flag == 1 and len(line) <= 4:
                flag = 0
        FConfig.close()


class FTSend(QtCore.QThread):
    FTFile_signal = QtCore.pyqtSignal(int, int, str)
    Bar_signal = QtCore.pyqtSignal(float)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        Ftime = float(SendTimer / 1000)
        Scount = 0
        count = 0
        flag = 0
        Sflag = 1
        clear_flag = 1
        if FItem == '道路指引':
            if FSub == '自车':
                Path = 'Script\MMI274\NTS\ziche.txt'
            if FSub == '左转':
                Path = 'Script\MMI274\NTS\TurnLeft.txt'
            if FSub == '右转':
                Path = 'Script\MMI274\NTS\TurnRight.txt'
            if FSub == '左前方':
                Path = 'Script\MMI274\NTS\FrontLeft.txt'
            if FSub == '右前方':
                Path = 'Script\MMI274\NTS\FrontRight.txt'
            if FSub == '左后方':
                Path = 'Script\MMI274\NTS\BackLeft.txt'
            if FSub == '右后方':
                Path = 'Script\MMI274\NTS\BackRight.txt'
            if FSub == '左转掉头':
                Path = 'Script\MMI274\NTS\TurnAround.txt'
            if FSub == '直行':
                Path = 'Script\MMI274\NTS\StraightLine.txt'
            if FSub == '到达途经点':
                Path = 'Script\MMI274\NTS\Place.txt'
            if FSub == '进入环岛':
                Path = 'Script\MMI274\NTS\Roundabout.txt'
            if FSub == '驶出环岛':
                Path = 'Script\MMI274\NTS\OutRoundabout.txt'
            if FSub == '到达服务区':
                Path = 'Script\MMI274\NTS\ServiceArea.txt'
            if FSub == '到达收费站':
                Path = 'Script\MMI274\NTS\TollGate.txt'
            if FSub == '到达目的地':
                Path = 'Script\MMI274\NTS\FinalPlace.txt'
            if FSub == '进入隧道':
                Path = 'Script\MMI274\NTS\Tunnel.txt'
            if FSub == '左侧进入环岛':
                Path = 'Script\MMI274\NTS\LeftRoundabout.txt'
            if FSub == '左侧驶出环岛':
                Path = 'Script\MMI274\NTS\OutLeftRoundabout.txt'
            if FSub == '右转掉头':
                Path = 'Script\MMI274\NTS\RightTurnAround.txt'
            if FSub == '顺行':
                Path = 'Script\MMI274\NTS\sx.txt'
            if FSub == '无效':
                Path = 'Script\MMI274\NTS\Invaild.txt'
            if FSub == '随机':
                Path = 'Script\MMI274\NTS\Random.txt'
            if FSub == '倒序':
                Path = 'Script\MMI274\NTS\Reverse.txt'
            FPath = open(Path, 'r')
            for line in FPath:
                Scount += 1
            FPath.close()
            NPath = open(Path, 'r')
            for Rline in NPath:
                if len(Rline) >= 5:
                    SuLine = Rline.split(' ')
                    Id = '0x' + SuLine[0]
                    Id = int(Id, 16)
                    data0 = '0x' + SuLine[1]
                    data0 = int(data0, 16)
                    data1 = '0x' + SuLine[2]
                    data1 = int(data1, 16)
                    data2 = '0x' + SuLine[3]
                    data2 = int(data2, 16)
                    data3 = '0x' + SuLine[4]
                    data3 = int(data3, 16)
                    data4 = '0x' + SuLine[5]
                    data4 = int(data4, 16)
                    data5 = '0x' + SuLine[6]
                    data5 = int(data5, 16)
                    data6 = '0x' + SuLine[7]
                    data6 = int(data6, 16)
                    data7 = '0x' + SuLine[8]
                    data7 = int(data7, 16)
                    frame = can.Frame(Id)
                    frame.dlc = 8
                    dev.start()
                    frame.data = [data0, data1, data2, data3, data4, data5, data6, data7]
                    self.FTFile_signal.emit(clear_flag, Sflag, str(frame))
                    dev.send(frame)
                    time.sleep(Ftime)
                count += 1
                clear_flag += 1
                if clear_flag >= 6000:
                    clear_flag = 0
                SendBar = float(count / Scount)
                self.Bar_signal.emit(SendBar)
            NPath.close()
        else:
            for line in FTname:
                new = str(line.decode('gb2312'))
                MathFlag = re.search(FItem, new)
                if MathFlag:
                    flag = 1
                if flag == 1 and len(line) >= 4:
                    new_line = new.split(' ')
                    if FunTest == new_line[0]:
                        pass
                    else:
                        if new_line[0] == FSub:
                            Path = str(new_line[1]).rstrip('\n')
                            FPath = open(Path, 'r')
                            for line in FPath:
                                Scount += 1
                            FPath.close()
                            NPath = open(Path, 'r')
                            for Rline in NPath:
                                if len(Rline) >= 5:
                                    SuLine = Rline.split(' ')
                                    Id = '0x' + SuLine[0]
                                    Id = int(Id, 16)
                                    data0 = '0x' + SuLine[1]
                                    data0 = int(data0, 16)
                                    data1 = '0x' + SuLine[2]
                                    data1 = int(data1, 16)
                                    data2 = '0x' + SuLine[3]
                                    data2 = int(data2, 16)
                                    data3 = '0x' + SuLine[4]
                                    data3 = int(data3, 16)
                                    data4 = '0x' + SuLine[5]
                                    data4 = int(data4, 16)
                                    data5 = '0x' + SuLine[6]
                                    data5 = int(data5, 16)
                                    data6 = '0x' + SuLine[7]
                                    data6 = int(data6, 16)
                                    data7 = '0x' + SuLine[8]
                                    data7 = int(data7, 16)
                                    frame = can.Frame(Id)
                                    frame.dlc = 8
                                    dev.start()
                                    frame.data = [data0, data1, data2, data3, data4, data5, data6, data7]
                                    self.FTFile_signal.emit(clear_flag, Sflag, str(frame))
                                    dev.send(frame)
                                    time.sleep(Ftime)
                                count += 1
                                clear_flag += 1
                                if clear_flag >= 60000:
                                    clear_flag = 0
                                SendBar = float(count / Scount) * 100
                                self.Bar_signal.emit(SendBar)
                            NPath.close()
                if flag == 1 and len(line) <= 4:
                    flag = 0

            FConfig.close()


class Model(QtCore.QThread):
    Model_signal = QtCore.pyqtSignal(int, int, str)
    ResponseResult = QtCore.pyqtSignal(int)
    RecMessage = QtCore.pyqtSignal(str)
    RecResult = QtCore.pyqtSignal(int)
    ModelResult = QtCore.pyqtSignal(int)
    TimeSignal = QtCore.pyqtSignal(str)
    Show_signal = QtCore.pyqtSignal(str)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        count = 1
        flag = 1
        if DUT_Model == "默认":
            # 获取寻址ID
            frame = can.Frame(CanID)
            frame.dlc = 3
            dev.start()
            frame.data = [0x02, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
            # 发送请求
            dev.send(frame)
            timeStart = datetime.datetime.now()
            self.Model_signal.emit(count, flag, str(frame))
            # 返回请求信息
            mess = dev.recv()
            # self.dev.serial.read()
            if frame.id == 0x7DF:
                if len(mess.data) == 0:
                    self.Show_signal.emit('')
                    result = u'功能寻址，默认模式切换HUD未回复，响应正确'
                    self.RecMessage.emit(result)
                else :
                    self.Show_signal.emit('')
                    result = u'功能寻址，默认模式切换HUD回复，响应错误'
                    self.RecMessage.emit(result)
            else:
                if len(mess.data) == 0:
                    self.Show_signal.emit('')
                    result = u'物理寻址，默认模式切换HUD未回复，响应错误'
                    self.RecMessage.emit(result)
                else:
                    timeEnd = datetime.datetime.now()
                    timeSleep = timeEnd - timeStart
                    self.TimeSignal.emit(str(timeSleep))
                    Mess = str(mess)
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.RecMessage.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[6, 80, 1, 0, 50, 1, 244, 85]':
                            result = u'系统已进入默认模式'
                            self.ModelResult.emit(1)
                            self.RecMessage.emit(result)
                        else:
                            if Data == 'Data=[3, 127, 16, 34, 0, 40, 0, 85]':
                                self.RecMessage.emit(u'条件未满足')
                            else:
                                self.RecResult.emit(1)
                    else:
                        self.RecResult.emit(0)
        if DUT_Model == "编程":
            frame = can.Frame(CanID)
            frame.dlc = 3
            dev.start()
            frame.data = [0x02, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
            dev.send(frame)
            timeStart = datetime.datetime.now()
            self.Model_signal.emit(count, flag, str(frame))
            mess = dev.recv()
            if CanID == 0x7DF:
                if len(mess.data) == 0:
                    self.Show_signal.emit('')
                    result = u'功能寻址，编程模式切换HUD未回复，响应正确'
                    self.RecMessage.emit(result)
                else:
                    self.Show_signal.emit('')
                    result = u'功能寻址，编程模式切换HUD回复，响应错误'
                    self.RecMessage.emit(result)
            else:
                if len(mess.data) == 0:
                    self.Show_signal.emit('')
                    result = u'物理寻址，编程模式切换HUD未回复，响应错误'
                    self.RecMessage.emit(result)
                else:
                    timeEnd = datetime.datetime.now()
                    timeSleep = timeEnd - timeStart
                    self.TimeSignal.emit(str(timeSleep))
                    Mess = str(mess)
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.RecMessage.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[6, 80, 2, 0, 50, 1, 244, 85]':
                            result = u'系统已进入编程模式'
                            self.ModelResult.emit(2)
                            self.RecMessage.emit(result)
                        else:
                            if Data == 'Data=[3, 127, 16, 34, 85, 85, 85, 85]':
                                self.RecMessage.emit(u'条件未满足，不能切换到编程模式')
                            else:
                                self.RecResult.emit(1)
                    else:
                        self.RecResult.emit(0)
        if DUT_Model == "扩展":
            frame = can.Frame(CanID)
            frame.dlc = 3
            dev.start()
            frame.data = [0x02, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
            dev.send(frame)
            timeStart = datetime.datetime.now()
            self.Model_signal.emit(count, flag, str(frame))
            mess = dev.recv()
            if CanID == 0x7DF:
                if len(mess.data) == 0:
                    self.Show_signal.emit('')
                    result = u'功能寻址，扩展模式切换HUD未回复，响应正确'
                    self.RecMessage.emit(result)
                else:
                    self.Show_signal.emit('')
                    result = u'功能寻址，扩展模式切换HUD回复，响应错误'
                    self.RecMessage.emit(result)
            else:
                if len(mess.data) == 0:
                    self.Show_signal.emit('')
                    result = u'物理寻址,扩展模式切换HUD未回复，响应错误'
                    self.RecMessage.emit(result)
                else:
                    timeEnd = datetime.datetime.now()
                    timeSleep = timeEnd - timeStart
                    self.TimeSignal.emit(str(timeSleep))
                    Mess = str(mess)
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.RecMessage.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[6, 80, 3, 0, 50, 1, 244, 85]':
                            result = u'系统已进入扩展模式'
                            self.ModelResult.emit(3)
                            self.RecMessage.emit(result)
                        else:
                            if Data == 'Data=[3, 127, 16, 34, 85, 85, 85, 85]':
                                self.RecMessage.emit(u'条件未满足，不能切换到扩展模式')
                            else:
                                self.RecResult.emit(1)
                    else:
                        self.RecResult.emit(0)


class DSCSender(QtCore.QThread):
    DSCSender_signal = QtCore.pyqtSignal(int, int, str)
    DSCRecv_signal = QtCore.pyqtSignal(str)
    DSCResult_signal = QtCore.pyqtSignal(int)
    TimeSignal = QtCore.pyqtSignal(str)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        count = 1
        flag = 1
        if SubUnSpportDSC == '子功能不支持':
            frame = can.Frame(CanID)
            frame.dlc = 8
            dev.start()
            frame.data = [0x02, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00]
            self.DSCSender_signal.emit(count, flag, str(frame))
            dev.send(frame)
            timeStart = datetime.datetime.now()
            mess = dev.recv()
            timeEnd = datetime.datetime.now()
            timeSleep = timeEnd - timeStart
            self.TimeSignal.emit(str(timeSleep))
            Mess = str(mess)
            new = Mess.split('\n')
            final = new[0] + new[1]
            self.DSCRecv_signal.emit(final)
            Pattern_id = re.compile(r'ID=0x7A9,')
            Match = Pattern_id.search(Mess)
            if Match:
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 16, 18, 85, 85, 85, 85]':
                    result = u'子功能不支持,系统响应正确'
                    self.DSCRecv_signal.emit(result)
                else:
                    result = u'子功能不支持,系统响应错误'
                    self.DSCRecv_signal.emit(result)
            else:
                self.DSCResult_signal.emit(0)

        if SubUnSpportDSC == '报文长度错误':
            frame = can.Frame(CanID)
            frame.dlc = 8
            RLen = random.randint(1, 7)
            if RLen == 2:
                RandomStr = u'随机数为报文正确长度，请继续点击发送测试'
                self.DSCRecv_signal.emit(RandomStr)
            else:
                if RLen == 1:
                    frame.data = [0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                if RLen == 3:
                    frame.data = [0x03, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                if RLen == 4:
                    frame.data = [0x04, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                if RLen == 5:
                    frame.data = [0x05, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                if RLen == 6:
                    frame.data = [0x06, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                if RLen == 7:
                    frame.data = [0x07, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                dev.start()
                self.DSCSender_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.DSCRecv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 16, 19, 85, 85, 85, 85]':
                        result = u'报文长度错误,系统响应正确'
                        self.DSCRecv_signal.emit(result)
                    else:
                        result = u'报文长度错误,系统响应错误'
                        self.DSCRecv_signal.emit(result)
                else:
                    self.DSCResult_signal.emit(0)

        if SubUnSpportDSC == "未满足条件-默认跳编程":
            frame = can.Frame(CanID)
            frame.dlc = 3
            dev.start()
            frame.data = [0x02, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
            dev.send(frame)
            self.DSCSender_signal.emit(count, flag, str(frame))
            mess = dev.recv()
            timeStart = datetime.datetime.now()
            Mess = str(mess)
            timeEnd = datetime.datetime.now()
            timeSleep = timeEnd - timeStart
            self.TimeSignal.emit(str(timeSleep))
            new = Mess.split('\n')
            final = new[0] + new[1]
            self.DSCRecv_signal.emit(final)
            Pattern_id = re.compile(r'ID=0x7A9,')
            Match = Pattern_id.search(Mess)
            if Match:
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 16, 34, 85, 85, 85, 85]':
                    result = u'条件未满足，系统响应正确'
                    self.DSCRecv_signal.emit(result)
                else:
                    result = u'条件未满足，系统响应错误'
                    self.DSCRecv_signal.emit(result)
            else:
                self.DSCResult_signal.emit(0)
        if SubUnSpportDSC == "未满足条件-编程跳扩展":
            frame = can.Frame(CanID)
            frame.dlc = 3
            dev.start()
            frame.data = [0x02, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
            dev.send(frame)
            timeStart = datetime.datetime.now()
            self.DSCSender_signal.emit(count, flag, str(frame))
            mess = dev.recv()
            Mess = str(mess)
            timeEnd = datetime.datetime.now()
            timeSleep = timeEnd - timeStart
            self.TimeSignal.emit(str(timeSleep))
            new = Mess.split('\n')
            final = new[0] + new[1]
            self.DSCRecv_signal.emit(final)
            Pattern_id = re.compile(r'ID=0x7A9,')
            Match = Pattern_id.search(Mess)
            if Match:
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 16, 34, 85, 85, 85, 85]':
                    result = u'条件未满足，系统响应正确'
                    self.DSCRecv_signal.emit(result)
                else:
                    result = u'条件未满足，系统响应错误'
                    self.DSCRecv_signal.emit(result)
            else:
                self.DSCResult_signal.emit(0)


class Send1(QtCore.QThread):
    Sender1_signal = QtCore.pyqtSignal(int, int, str)
    Recv_signal = QtCore.pyqtSignal(str)
    Result_signal = QtCore.pyqtSignal(int)
    ResponseResult = QtCore.pyqtSignal(int)
    Model_signal = QtCore.pyqtSignal(int)
    TimeSignal = QtCore.pyqtSignal(str)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        count = 1
        flag = 1
        if Ser == '电控单元复位':
            if Response == '硬件复位':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[2, 81, 1, 85, 85, 85, 85, 85]':
                        result = u'硬件复位，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'硬件复位，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

            if Response == '钥匙开关复位':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x11, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[2, 81, 2, 85, 85, 85, 85, 85]':
                        result = u'钥匙开关复位，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'钥匙开关复位，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)
            if Response == '软件复位':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[2, 81, 3, 85, 85, 85, 85, 85]':
                        result = u'软件复位，系统响应正确'
                        self.Recv_signal.emit(result)
                        self.Model_signal.emit(1)
                    else:
                        result = u'软件复位，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if Ser == '诊断设备在线':
            if Response == '诊断':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[2, 126, 0, 85, 85, 85, 85, 85]':
                        result = u'诊断设备在线，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'诊断设备在线，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if Ser == '清除诊断信息':
            if Response == 'HUD系统':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x04, 0x14, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                        result = u'清除HUD系统诊断信息,系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'清除HUD系统诊断信息,系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

            if Response == '所有组（所有DTC）':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x04, 0x14, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                        result = u'清除所有组诊断信息,系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'清除所有组诊断信息,系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if Ser == '安全访问-种子':
            if Response == '请求级别1种子':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    security = str(new[1])
                    sub = security.split(',')
                    res = hex(int(sub[3])) + " " + hex(int(sub[4])) + ' ' + hex(int(sub[5])) + ' ' + hex(int(sub[6]))
                    if res == '00 00 00 00' or res == 'FF FF FF FF':
                        result = u'种子值非法'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'级别1种子值是：' + res
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

            if Response == '请求级别2种子':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x27, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    security = str(new[1])
                    sub = security.split(',')
                    res = hex(int(sub[3])) + " " + hex(int(sub[4])) + ' ' + hex(int(sub[5])) + ' ' + hex(int(sub[6]))
                    if res == '00 00 00 00' or res == 'FF FF FF FF':
                        result = u'种子值非法'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'级别2种子值是：' + res
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)
        '''
        if Ser == '安全访问-密钥':
            if Response == '请求级别1密钥':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                print final
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    security = str(new[1])
                    sub = security.split(',')
                    res = hex(int(sub[3])) + " " + hex(int(sub[4])) + ' ' + hex(int(sub[5])) + ' ' + hex(int(sub[6]))
                    if res == '00 00 00 00' or res == 'FF FF FF FF':
                        result = u'级别1密钥值非法'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'级别1密钥是：' + res
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

            if Response == '请求级别2密钥':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x27, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = datetime.datetime.now()
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    security = str(new[1])
                    sub = security.split(',')
                    res = hex(int(sub[3])) + " " + hex(int(sub[4])) + ' ' + hex(int(sub[5])) + ' ' + hex(int(sub[6]))
                    if res == '00 00 00 00' or res == 'FF FF FF FF':
                        result = u'级别2密钥值非法'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'级别2密钥是：' + res
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)
                '''
        if Ser == '通信控制':
            if Response == '使能接收和发送':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[2, 104, 0, 85, 85, 85, 85, 85]':
                        result = u'使能接收且发送报文，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'使能接收且发送报文，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

            if Response == '使能接收且禁止发送':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x28, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[2, 104, 1, 85, 85, 85, 85, 85]':
                        result = u'使能接收且禁止发送，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'使能接收且禁止发送，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

            if Response == '禁止接收且使能发送':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x28, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[2, 104, 2, 85, 85, 85, 85, 85]':
                    result = u'禁止接收且使能发送，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'禁止接收且使能发送，系统响应错误'
                    self.Recv_signal.emit(result)
            # else:
            # self.Result_signal.emit(0)

            if Response == '禁止接收且禁止发送':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x28, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[2, 104, 3, 85, 85, 85, 85, 85]':
                    result = u'禁止接收且禁止发送，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'禁止接收且禁止发送，系统响应错误'
                    self.Recv_signal.emit(result)
            # else:
            # self.Result_signal.emit(0)

        if Ser == '控制DTC设置':
            if Response == '打开':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x02,0x85,0x01,0x00,0x00,0x00,0x00,0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[2, 197, 1, 85, 85, 85, 85, 85]':
                    result = u'打开DTC设置，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'打开DTC设置，系统响应错误'
                    self.Recv_signal.emit(result)
            # else:
            # self.Result_signal.emit(0)

            if Response == '关闭':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[2, 197, 2, 85, 85, 85, 85, 85]':
                    result = u'关闭DTC设置，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'关闭DTC设置，系统响应错误'
                    self.Recv_signal.emit(result)
            # else:
            # self.Result_signal.emit(0)

        if Ser == '读取DTC数量':
            if Response == '报告DTC数量':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x19, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00]
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data[0:20] == 'Data=[6, 89, 1, 9, 1':
                    result = u'报告DTC数量，系统响应正确'
                    self.Recv_signal.emit(result)
                    res = str(new[1])
                    sub = res.split(',')
                    if int(sub[5]) == 0:
                        DTCount = int(sub[6])
                    else:
                        STR1 = hex(int(sub[5]))
                        if int(sub[6]) == 0:
                            STR2 = '0'
                        else:
                            STR2 = str(hex(int(sub[6]))).lstrip('0x')
                        STR = STR1 + STR2
                        DTCount = int(STR, 16)
                    result = u'DTC数量：' + str(DTCount)
                    self.Recv_signal.emit(result)
                else:
                    result = u'报告DTC数量，系统响应错误'
                    self.Recv_signal.emit(result)
            # else:
            # self.Result_signal.emit(0)

        if Response == '报告DTC':
            frame = can.Frame(CanID)
            frame.dlc = 8
            dev.start()
            frame.data = [0x03, 0x19, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00]
            self.Sender1_signal.emit(count, flag, str(frame))
            dev.send(frame)
            timeStart = datetime.datetime.now()
            mess = dev.recv()
            timeEnd = datetime.datetime.now()
            timeSleep = timeEnd - timeStart
            self.TimeSignal.emit(str(timeSleep))
            Mess = str(mess)
            new = Mess.split('\n')
            final = new[0] + new[1]
            self.Recv_signal.emit(final)
            Pattern_id = re.compile(r'ID=0x7A9,')
            Match = Pattern_id.search(Mess)
            if Match:
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data[0:20] == 'Data=[6, 89, 1, 9, 1':
                    res = str(new[1])
                    sub = res.split(',')
                    if int(sub[5]) == 0:
                        DTCount = int(sub[6])
                    else:
                        STR1 = hex(int(sub[5]))
                        if int(sub[6]) == 0:
                            STR2 = '0'
                        else:
                            STR2 = str(hex(int(sub[6]))).lstrip('0x')
                        STR = STR1 + STR2
                        DTCount = int(STR, 16)
                    if DTCount == 0:
                        result = u'DTC数量为0！'
                        self.Recv_signal.emit(result)
                    else:
                        frame.data = [0x03, 0x19, 0x02, 0x09, 0x00, 0x00, 0x00, 0x00]
                        dev.send(frame)
                        timeStart = datetime.datetime.now()
                        self.Sender1_signal.emit(count, flag, str(frame))
                        mess = dev.recv()
                        timeEnd = datetime.datetime.now()
                        timeSleep = timeEnd - timeStart
                        self.TimeSignal.emit(str(timeSleep))
                        data0 = str(mess)
                        new = data0.split('\n')
                        final = new[0] + new[1]
                        self.Recv_signal.emit(final)
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(data0)
                        Data = DataGroup.group()
                        DataList = Data.split(',')
                        str0 = str(hex(int(DataList[4].lstrip(' ')))).lstrip('0x')
                        str1 = str(hex(int(DataList[5].lstrip(' ')))).lstrip('0x')
                        str2 = str(hex(int(DataList[6].lstrip(' ')))).lstrip('0x')
                        str3 = str(hex(int(DataList[7].lstrip(' ').rstrip(']')))).lstrip('0x')
                        if DTCount == 1:
                            DTCode0 = str0
                            DTCode1 = str1
                            DTCode2 = str2
                            DTCode = DTCode0 + DTCode1 + DTCode2
                        else:
                            DTCode0 = str1 + str2 + str3 + ' '
                            frame.data = [0x30, 0x0A, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00]
                            dev.send(frame)
                            timeStart = datetime.datetime.now()
                            self.Sender1_signal.emit(count, flag, str(frame))
                            mess = dev.recv()
                            timeEnd = datetime.datetime.now()
                            timeSleep = timeEnd - timeStart
                            self.TimeSignal.emit(str(timeSleep))
                            data1 = str(mess)
                            new = data1.split('\n')
                            final = new[0] + new[1]
                            self.Recv_signal.emit(final)
                            Pattern_Data = re.compile(r'Data=.+')
                            DataGroup = Pattern_Data.search(data1)
                            Data = DataGroup.group()
                            DaList = Data.split(',')
                            str4 = str(hex(int(DaList[2].lstrip(' ')))).lstrip('0x')
                            str5 = str(hex(int(DaList[3].lstrip(' ')))).lstrip('0x')
                            str6 = str(hex(int(DaList[4].lstrip(' ')))).lstrip('0x')
                            str7 = str(hex(int(DaList[6].lstrip(' ')))).lstrip('0x')
                            str8 = str(hex(int(DaList[7].lstrip(' ').rstrip(']')))).lstrip('0x')
                            DTCode1 = str4 + str5 + str6 + ' '
                            if DTCount == 2:
                                DTCode = DTCode0 + DTCode1
                            else:
                                mess = dev.recv()
                                data2 = str(mess)
                                new = data2.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(data2)
                                Data = DataGroup.group()
                                DList = Data.split(',')
                                str9 = str(hex(int(DList[1].lstrip(' ')))).lstrip('0x')
                                DTCode2 = str7 + str8 + str9 + ' '
                                str10 = str(hex(int(DList[3].lstrip(' ')))).lstrip('0x')
                                str11 = str(hex(int(DList[4].lstrip(' ')))).lstrip('0x')
                                str12 = str(hex(int(DList[5].lstrip(' ')))).lstrip('0x')
                                DTCode3 = str10 + str11 + str12 + ' '
                                str13 = str(hex(int(DList[7].lstrip(' ').rstrip(']')))).lstrip('0x')
                                if DTCount <= 4:
                                    if DTCount == 3:
                                        DTCode = DTCode0 + DTCode1 + DTCode2
                                    if DTCount == 4:
                                        DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3
                                else:
                                    mess = dev.recv()
                                    data3 = str(mess)
                                    new = data3.split('\n')
                                    final = new[0] + new[1]
                                    self.Recv_signal.emit(final)
                                    Pattern_Data = re.compile(r'Data=.+')
                                    DataGroup = Pattern_Data.search(data3)
                                    Data = DataGroup.group()
                                    DatList = Data.split(',')
                                    str14 = str(hex(int(DatList[1].lstrip(' ')))).lstrip('0x')
                                    str15 = str(hex(int(DatList[2].lstrip(' ')))).lstrip('0x')
                                    DTCode4 = str13 + str14 + str15 + ' '
                                    str16 = str(hex(int(DatList[4].lstrip(' ')))).lstrip('0x')
                                    str17 = str(hex(int(DatList[5].lstrip(' ')))).lstrip('0x')
                                    str18 = str(hex(int(DatList[6].lstrip(' ')))).lstrip('0x')
                                    DTCode5 = str16 + str17 + str18 + ' '
                                    if DTCount <= 6:
                                        if DTCount == 5:
                                            DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3 + DTCode4
                                        if DTCount == 6:
                                            DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3 + DTCode4 + DTCode5
                                    else:
                                        mess = dev.recv()
                                        data4 = str(mess)
                                        new = data4.split('\n')
                                        final = new[0] + new[1]
                                        self.Recv_signal.emit(final)
                                        Pattern_Data = re.compile(r'Data=.+')
                                        DataGroup = Pattern_Data.search(data4)
                                        Data = DataGroup.group()
                                        DtList = Data.split(',')
                                        str19 = str(hex(int(DtList[1].lstrip(' ')))).lstrip('0x')
                                        str20 = str(hex(int(DtList[2].lstrip(' ')))).lstrip('0x')
                                        str21 = str(hex(int(DtList[3].lstrip(' ')))).lstrip('0x')
                                        DTCode6 = str19 + str20 + str21 + ' '
                                        str22 = str(hex(int(DtList[5].lstrip(' ')))).lstrip('0x')
                                        str23 = str(hex(int(DtList[6].lstrip(' ')))).lstrip('0x')
                                        str24 = str(hex(int(DtList[7].lstrip(' ').rstrip(']')))).lstrip('0x')
                                        DTCode7 = str22 + str23 + str24 + ' '
                                        if DTCount <= 8:
                                            if DTCount == 7:
                                                DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3 + DTCode4 + DTCode5 + DTCode6
                                            if DTCount == 8:
                                                DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3 + DTCode4 + DTCode5 + DTCode6 + DTCode7
                                                temp = str(dev.recv())
                                        else:
                                            mess = dev.recv()
                                            data5 = str(mess)
                                            new = data5.split('\n')
                                            final = new[0] + new[1]
                                            self.Recv_signal.emit(final)
                                            Pattern_Data = re.compile(r'Data=.+')
                                            DataGroup = Pattern_Data.search(data5)
                                            Data = DataGroup.group()
                                            DfList = Data.split(',')
                                            str25 = str(hex(int(DfList[2].lstrip(' ')))).lstrip('0x')
                                            str26 = str(hex(int(DfList[3].lstrip(' ')))).lstrip('0x')
                                            str27 = str(hex(int(DfList[4].lstrip(' ')))).lstrip('0x')
                                            DTCode8 = str25 + str26 + str27 + ' '
                                            str28 = str(hex(int(DfList[6].lstrip(' ')))).lstrip('0x')
                                            str29 = str(hex(int(DfList[7].lstrip(' ').rstrip(']')))).lstrip('0x')
                                            if DTCount < 10:
                                                DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3 + DTCode4 + DTCode5 + DTCode6 + DTCode7 + DTCode8
                                            else:
                                                mess = dev.recv()
                                                data6 = str(mess)
                                                new = data6.split('\n')
                                                final = new[0] + new[1]
                                                self.Recv_signal.emit(final)
                                                Pattern_Data = re.compile(r'Data=.+')
                                                DataGroup = Pattern_Data.search(data6)
                                                Data = DataGroup.group()
                                                DsList = Data.split(',')
                                                str30 = str(hex(int(DsList[1].lstrip(' ')))).lstrip('0x')
                                                DTCode9 = str28 + str29 + str30 + ' '
                                                str31 = str(hex(int(DsList[3].lstrip(' ')))).lstrip('0x')
                                                str32 = str(hex(int(DsList[4].lstrip(' ')))).lstrip('0x')
                                                str33 = str(hex(int(DsList[5].lstrip(' ')))).lstrip('0x')
                                                DTCode10 = str31 + str32 + str33 + ' '
                                                str34 = str(hex(int(DsList[7].lstrip(' ').rstrip(']')))).lstrip('0x')
                                                if DTCount <= 11:
                                                    if DTCount == 10:
                                                        DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3 + DTCode4 + DTCode5 + DTCode6 + DTCode7 + DTCode8 + DTCode9
                                                    if DTCount == 11:
                                                        DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3 + DTCode4 + DTCode5 + DTCode6 + DTCode7 + DTCode8 + DTCode9 + DTCode10
                                                else:
                                                    mess = dev.recv()
                                                    data7 = str(mess)
                                                    new = data7.split('\n')
                                                    final = new[0] + new[1]
                                                    self.Recv_signal.emit(final)
                                                    Pattern_Data = re.compile(r'Data=.+')
                                                    DataGroup = Pattern_Data.search(data7)
                                                    Data = DataGroup.group()
                                                    D7List = Data.split(',')
                                                    str35 = str(hex(int(D7List[1].lstrip(' ')))).lstrip('0x')
                                                    str36 = str(hex(int(D7List[2].lstrip(' ')))).lstrip('0x')
                                                    DTCode11 = str34 + str35 + str36 + ' '
                                                    str37 = str(hex(int(D7List[4].lstrip(' ')))).lstrip('0x')
                                                    str38 = str(hex(int(D7List[5].lstrip(' ')))).lstrip('0x')
                                                    str39 = str(hex(int(D7List[6].lstrip(' ')))).lstrip('0x')
                                                    DTCode12 = str37 + str38 + str39 + ' '
                                                    if DTCount <= 13:
                                                        if DTCount == 12:
                                                            DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3 + DTCode4 + DTCode5 + DTCode6 + DTCode7 + DTCode8 + DTCode9 + DTCode10 + DTCode11
                                                        if DTCount == 13:
                                                            DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3 + DTCode4 + DTCode5 + DTCode6 + DTCode7 + DTCode8 + DTCode9 + DTCode10 + DTCode11 + DTCode12
                                                    else:
                                                        mess = dev.recv()
                                                        data8 = str(mess)
                                                        new = data8.split('\n')
                                                        final = new[0] + new[1]
                                                        self.Recv_signal.emit(final)
                                                        Pattern_Data = re.compile(r'Data=.+')
                                                        DataGroup = Pattern_Data.search(data8)
                                                        Data = DataGroup.group()
                                                        D8List = Data.split(',')
                                                        str40 = str(hex(int(D8List[1].lstrip(' ')))).lstrip('0x')
                                                        str41 = str(hex(int(D8List[2].lstrip(' ')))).lstrip('0x')
                                                        if len(str41) < 2:
                                                            str41 = '0' + str41
                                                        str42 = str(hex(int(D8List[3].lstrip(' ')))).lstrip('0x')
                                                        DTCode13 = str40 + str41 + str42 + ' '
                                                        if DTCount == 14:
                                                            DTCode = DTCode0 + DTCode1 + DTCode2 + DTCode3 + DTCode4 + DTCode5 + DTCode6 + DTCode7 + DTCode8 + DTCode9 + DTCode10 + DTCode11 + DTCode12 + DTCode13
                                                        else:
                                                            result = u'DTC故障码数量超过最大值14'
                                                            self.Recv_signal.emit(result)
                        result = u'DTC数量 ' + str(DTCount) + u' DTC故障码:' + DTCode
                        self.Recv_signal.emit(result)
                else:
                    result = u'无法查询到DTC数量！'
                    self.Recv_signal.emit(result)
            else:
                self.Result_signal.emit(0)

        if Ser == '读取数据':
            frame = can.Frame(CanID)
            frame.dlc = 8
            dev.start()
            if Response == '车辆识别号':
                frame.data = [0x03, 0x22, 0xF1, 0x90, 0x00, 0x00, 0x00, 0x00]
            if Response == '零件号':
                frame.data = [0x03, 0x22, 0xF1, 0x87, 0x00, 0x00, 0x00, 0x00]
            if Response == '供应商名称':
                frame.data = [0x03, 0x22, 0xF1, 0x8A, 0x00, 0x00, 0x00, 0x00]
            if Response == 'ECU名称':
                frame.data = [0x03, 0x22, 0xF1, 0x97, 0x00, 0x00, 0x00, 0x00]
            if Response == '硬件版本号':
                frame.data = [0x03, 0x22, 0xF1, 0x93, 0x00, 0x00, 0x00, 0x00]
            if Response == '软件版本号':
                frame.data = [0x03, 0x22, 0xF1, 0x95, 0x00, 0x00, 0x00, 0x00]
            if Response == 'ECU流水编号':
                frame.data = [0x03, 0x22, 0xF1, 0x8C, 0x00, 0x00, 0x00, 0x00]
            self.Sender1_signal.emit(count, flag, str(frame))
            dev.send(frame)
            timeStart = datetime.datetime.now()
            mess = dev.recv()
            timeEnd = datetime.datetime.now()
            timeSleep = timeEnd - timeStart
            self.TimeSignal.emit(str(timeSleep))
            Mess = str(mess)
            new = Mess.split('\n')
            final = new[0] + new[1]
            self.Recv_signal.emit(final)
            Pattern_id = re.compile(r'ID=0x7A9,')
            Match = Pattern_id.search(Mess)
            if Match:
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                DList = Data.split(',')
                DataLen = int(DList[1].lstrip(' '))
                Code0 = str(hex(int(DList[5].lstrip(' ')))).lstrip('0x')
                InputCode0 = binascii.a2b_hex(Code0)
                Code1 = str(hex(int(DList[6].lstrip(' ')))).lstrip('0x')
                InputCode1 = binascii.a2b_hex(Code1)
                Code2 = str(hex(int(DList[7].lstrip(' ').rstrip(']')))).lstrip('0x')
                InputCode2 = binascii.a2b_hex(Code2)
                frame.data = [0x30, 0x0A, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00]
                dev.send(frame)
                timeStart = datetime.datetime.now()
                self.Sender1_signal.emit(count, flag, str(frame))

                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                data = str(mess)
                new = data.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)

                if DataLen > 13:
                    mess = dev.recv()
                    data1 = str(mess)
                    new = data1.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(data)
                Data = DataGroup.group()
                DataList = Data.split(',')
                Code3 = str(hex(int(DataList[1].lstrip(' ')))).lstrip('0x')
                InputCode3 = binascii.a2b_hex(Code3)
                Code4 = str(hex(int(DataList[2].lstrip(' ')))).lstrip('0x')
                InputCode4 = binascii.a2b_hex(Code4)
                Code5 = str(hex(int(DataList[3].lstrip(' ')))).lstrip('0x')
                InputCode5 = binascii.a2b_hex(Code5)
                Code6 = str(hex(int(DataList[4].lstrip(' ')))).lstrip('0x')
                InputCode6 = binascii.a2b_hex(Code6)
                Code7 = str(hex(int(DataList[5].lstrip(' ')))).lstrip('0x')
                InputCode7 = binascii.a2b_hex(Code7)
                Code8 = str(hex(int(DataList[6].lstrip(' ')))).lstrip('0x')
                InputCode8 = binascii.a2b_hex(Code8)
                Code9 = str(hex(int(DataList[7].lstrip(' ').rstrip(']')))).lstrip('0x')
                InputCode9 = binascii.a2b_hex(Code9)
                if DataLen > 13:
                    DataGroup = Pattern_Data.search(data1)
                    Data = DataGroup.group()
                    DataList = Data.split(',')
                    Code10 = str(hex(int(DataList[1].lstrip(' ')))).lstrip('0x')
                    InputCode10 = binascii.a2b_hex(Code10)
                    Code11 = str(hex(int(DataList[2].lstrip(' ')))).lstrip('0x')
                    InputCode11 = binascii.a2b_hex(Code11)
                    Code12 = str(hex(int(DataList[3].lstrip(' ')))).lstrip('0x')
                    InputCode12 = binascii.a2b_hex(Code12)
                    Code13 = str(hex(int(DataList[4].lstrip(' ')))).lstrip('0x')
                    InputCode13 = binascii.a2b_hex(Code13)
                    Code14 = str(hex(int(DataList[5].lstrip(' ')))).lstrip('0x')
                    InputCode14 = binascii.a2b_hex(Code14)
                    Code15 = str(hex(int(DataList[6].lstrip(' ')))).lstrip('0x')
                    InputCode15 = binascii.a2b_hex(Code15)
                    Code16 = str(hex(int(DataList[7].lstrip(' ').rstrip(']')))).lstrip('0x')
                    InputCode16 = binascii.a2b_hex(Code16)
                if Response == '车辆识别号':
                    try:
                        InputCode00 = InputCode0 + InputCode1 + InputCode2 + InputCode3 + InputCode4 + InputCode5 + InputCode6 + InputCode7 + InputCode8
                        InputCode01 = InputCode9 + InputCode10 + InputCode11 + InputCode12 + InputCode13 + InputCode14 + InputCode15 + InputCode16
                        result = u'车辆识别号:' + InputCode00 + InputCode01
                        self.Recv_signal.emit(result)
                    except:
                        result = u'系统回复的车辆识别号长度不是0x14'
                        self.Recv_signal.emit(result)
                if Response == '零件号':
                    if InputCode12 == ' ' or InputCode13 == ' ' or InputCode14 == ' ' or InputCode15 == ' ' or InputCode16 == ' ':
                        result = u'读取的零件号长度大于12个字节'
                        self.Recv_signal.emit(result)
                    InputCode00 = InputCode0 + InputCode1 + InputCode2 + InputCode3 + InputCode4 + InputCode5 + InputCode6 + InputCode7 + InputCode8
                    InputCode01 = InputCode9 + InputCode10 + InputCode11
                    result = u'零件号:' + InputCode00 + InputCode01
                    self.Recv_signal.emit(result)
                if Response == '供应商名称':
                    InputCode = InputCode0 + InputCode1 + InputCode2 + InputCode3 + InputCode4 + InputCode5 + InputCode6 + InputCode7 + InputCode8 + InputCode9
                    result = u'供应商名称:' + InputCode
                    self.Recv_signal.emit(result)
                if Response == 'ECU名称':
                    InputCode = InputCode0 + InputCode1 + InputCode2 + InputCode3 + InputCode4 + InputCode5 + InputCode6 + InputCode7 + InputCode8 + InputCode9
                    result = u'ECU名称:' + InputCode
                    self.Recv_signal.emit(result)
                if Response == '硬件版本号':
                    if InputCode8 == ' ' or InputCode9 == ' ':
                        result = u'读取的硬件版本号长度大于8个字节'
                        self.Recv_signal.emit(result)
                    InputCode = InputCode0 + InputCode1 + InputCode2 + InputCode3 + InputCode4 + InputCode5 + InputCode6 + InputCode7
                    result = u'硬件版本号:' + InputCode
                    self.Recv_signal.emit(result)
                if Response == '软件版本号':
                    if InputCode8 == ' ' or InputCode9 == ' ':
                        result = u'读取的软件版本号长度大于8个字节'
                        self.Recv_signal.emit(result)
                    InputCode = InputCode0 + InputCode1 + InputCode2 + InputCode3 + InputCode4 + InputCode5 + InputCode6 + InputCode7
                    result = u'软件版本号:' + InputCode
                    self.Recv_signal.emit(result)
                if Response == 'ECU流水编号':
                    try:
                        if InputCode14 == ' ' or InputCode15 == ' ' or InputCode16 == ' ':
                            result = u'读取的ECU流水编号长度大于14个字节'
                            self.Recv_signal.emit(result)
                        InputCode00 = InputCode0 + InputCode1 + InputCode2 + InputCode3 + InputCode4 + InputCode5 + InputCode6 + InputCode7 + InputCode8
                        InputCode01 = InputCode9 + InputCode10 + InputCode11 + InputCode12 + InputCode13
                        result = u'ECU流水编号:' + InputCode00 + InputCode01
                        self.Recv_signal.emit(result)
                    except:
                        result = u'系统回复的ECU流水编号长度不是0x11'
                        self.Recv_signal.emit(result)
            else:
                self.Result_signal.emit(0)

        if Ser == '写入数据':
            FCFlag = 0
            Cal = []
            Key = []

            InputLen = len(InputMessage)
            if InputLen == 0:
                pass
            else:
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                # print '发送请求：', frame
                self.Sender1_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()

                # print '返回请求：', mess
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                # mess=['ID=0x7A9, DLC=8, standard, data',' Data=[6, 103, 1, 18, 22, 225, 120, 85]']
                # new[1]= '\tData=[6, 103, 1, 18, 22, 225, 120, 85]'
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    res = str(new[1])
                    sub = res.split(',')
                    Cal.append(int(sub[3]) ^ 17)
                    Cal.append(int(sub[4]) ^ 228)
                    Cal.append(int(sub[5]) ^ 104)
                    Cal.append(int(sub[6]) ^ 44)

                    key0 = hex(Cal[2] & 0xf0 << 4)
                    key0 = int(key0, 16)
                    key1 = hex(Cal[3] & 0xf0)
                    key1 = int(key1, 16)
                    Key.append(key0 | key1)

                    key2 = hex((Cal[3] & 0x2f) << 2)
                    key2 = int(key2, 16)
                    key3 = hex(Cal[1] & 0x03)
                    key3 = int(key3, 16)
                    Key.append(key2 | key3)

                    key4 = hex((Cal[1] & 0xfc) >> 2)
                    key4 = int(key4, 16)
                    key5 = hex(Cal[0] & 0xc0)
                    key5 = int(key5, 16)
                    Key.append(key4 | key5)

                    key6 = hex((Cal[0] & 0x0f) << 4)
                    key6 = int(key6, 16)
                    key7 = hex(Cal[2] & 0x0f)
                    key7 = int(key7, 16)
                    Key.append(key6 | key7)

                    # frame.data=[0x02,0x27,0x02,security1,security2,security3,security4,0x00]
                    # time.sleep(60)
                    frame.data = [0x06, 0x27, 0x02, Key[0], Key[1], Key[2], Key[3], 0x00]

                    # frame.data=[0x06,0x27,0x02,0x00,0x11,0x22,0x33,0x00]
                    # print '发送计算结果，种子比对：',frame.data
                    dev.send(frame)
                    timeStart = datetime.datetime.now()
                    self.Sender1_signal.emit(count, flag, str(frame))
                    mess = dev.recv()
                    # print '返回比对结果',mess
                    timeEnd = datetime.datetime.now()
                    timeSleep = timeEnd - timeStart
                    self.TimeSignal.emit(str(timeSleep))
                    Mess = str(mess)
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)

                    if Match:
                        if InputLen <= 4:
                            if InputLen == 1:
                                Input0 = binascii.b2a_hex(InputMessage)
                                temp0 = '0x' + str(Input0)
                                data0 = int(temp0, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x04, 0x2E, 0xF1, 0x90, data0, 0x00, 0x00, 0x00]
                                if Response == '零件号':
                                    frame.data = [0x04, 0x2E, 0xF1, 0x87, data0, 0x00, 0x00, 0x00]
                                if Response == '供应商名称':
                                    frame.data = [0x04, 0x2E, 0xF1, 0x8A, data0, 0x00, 0x00, 0x00]
                                if Response == 'ECU名称':
                                    frame.data = [0x04, 0x2E, 0xF1, 0x97, data0, 0x00, 0x00, 0x00]
                                if Response == '硬件版本号':
                                    frame.data = [0x04, 0x2E, 0xF1, 0x93, data0, 0x00, 0x00, 0x00]
                                if Response == '软件版本号':
                                    frame.data = [0x04, 0x2E, 0xF1, 0x95, data0, 0x00, 0x00, 0x00]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x04, 0x2E, 0xF1, 0x8C, data0, 0x00, 0x00, 0x00]
                            if InputLen == 2:
                                Input0 = binascii.b2a_hex(InputMessage[0])
                                temp0 = '0x' + str(Input0)
                                Input1 = binascii.b2a_hex(InputMessage[1])
                                temp1 = '0x' + str(Input1)
                                data0 = int(temp0, 16)
                                data1 = int(temp1, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x05, 0x2E, 0xF1, 0x90, data0, data1, 0x00, 0x00]
                                if Response == '零件号':
                                    frame.data = [0x05, 0x2E, 0xF1, 0x87, data0, data1, 0x00, 0x00]
                                if Response == '供应商名称':
                                    frame.data = [0x05, 0x2E, 0xF1, 0x8A, data0, data1, 0x00, 0x00]
                                if Response == 'ECU名称':
                                    frame.data = [0x05, 0x2E, 0xF1, 0x97, data0, data1, 0x00, 0x00]
                                if Response == '硬件版本号':
                                    frame.data = [0x05, 0x2E, 0xF1, 0x93, data0, data1, 0x00, 0x00]
                                if Response == '软件版本号':
                                    frame.data = [0x05, 0x2E, 0xF1, 0x95, data0, data1, 0x00, 0x00]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x05, 0x2E, 0xF1, 0x8C, data0, data1, 0x00, 0x00]
                            if InputLen == 3:
                                Input0 = binascii.b2a_hex(InputMessage[0])
                                temp0 = '0x' + str(Input0)
                                Input1 = binascii.b2a_hex(InputMessage[1])
                                temp1 = '0x' + str(Input1)
                                Input2 = binascii.b2a_hex(InputMessage[2])
                                temp2 = '0x' + str(Input2)
                                data0 = int(temp0, 16)
                                data1 = int(temp1, 16)
                                data2 = int(temp2, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x06, 0x2E, 0xF1, 0x90, data0, data1, data2, 0x00]
                                if Response == '零件号':
                                    frame.data = [0x06, 0x2E, 0xF1, 0x87, data0, data1, data2, 0x00]
                                if Response == '供应商名称':
                                    frame.data = [0x06, 0x2E, 0xF1, 0x8A, data0, data1, data2, 0x00]
                                if Response == 'ECU名称':
                                    frame.data = [0x06, 0x2E, 0xF1, 0x97, data0, data1, data2, 0x00]
                                if Response == '硬件版本号':
                                    frame.data = [0x06, 0x2E, 0xF1, 0x93, data0, data1, data2, 0x00]
                                if Response == '软件版本号':
                                    frame.data = [0x06, 0x2E, 0xF1, 0x95, data0, data1, data2, 0x00]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x06, 0x2E, 0xF1, 0x8C, data0, data1, data2, 0x00]
                            if InputLen == 4:
                                Input0 = binascii.b2a_hex(InputMessage[0])
                                temp0 = '0x' + str(Input0)
                                Input1 = binascii.b2a_hex(InputMessage[1])
                                temp1 = '0x' + str(Input1)
                                Input2 = binascii.b2a_hex(InputMessage[2])
                                temp2 = '0x' + str(Input2)
                                Input3 = binascii.b2a_hex(InputMessage[3])
                                temp3 = '0x' + str(Input3)
                                data0 = int(temp0, 16)
                                data1 = int(temp1, 16)
                                data2 = int(temp2, 16)
                                data3 = int(temp3, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x07, 0x2E, 0xF1, 0x90, data0, data1, data2, data3]
                                if Response == '零件号':
                                    frame.data = [0x07, 0x2E, 0xF1, 0x87, data0, data1, data2, data3]
                                if Response == '供应商名称':
                                    frame.data = [0x07, 0x2E, 0xF1, 0x8A, data0, data1, data2, data3]
                                if Response == 'ECU名称':
                                    frame.data = [0x07, 0x2E, 0xF1, 0x97, data0, data1, data2, data3]
                                if Response == '硬件版本号':
                                    frame.data = [0x07, 0x2E, 0xF1, 0x93, data0, data1, data2, data3]
                                if Response == '软件版本号':
                                    frame.data = [0x07, 0x2E, 0xF1, 0x95, data0, data1, data2, data3]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x07, 0x2E, 0xF1, 0x8C, data0, data1, data2, data3]
                            dev.send(frame)
                            timeStart = datetime.datetime.now()
                            self.Sender1_signal.emit(count, flag, str(frame))
                            mess = dev.recv()
                            timeEnd = datetime.datetime.now()
                            timeSleep = datetime.datetime.now()
                            self.TimeSignal.emit(str(timeSleep))
                            Mess = str(mess)
                            new = Mess.split('\n')
                            final = new[0] + new[1]
                            self.Recv_signal.emit(final)
                            Pattern_Data = re.compile(r'Data=.+')
                            DataGroup = Pattern_Data.search(Mess)
                            Data = DataGroup.group()
                            if Response == '车辆识别号':
                                if Data == 'Data=[3, 110, 241, 144, 85, 85, 85, 85]':
                                    result = u'车辆识别号已写入'
                                    self.Recv_signal.emit(result)
                                else:
                                    result = u'车辆识别号写入肯定响应回复错误'
                                    self.Recv_signal.emit(result)
                            if Response == '零件号':
                                if Data == 'Data=[3, 110, 241, 135, 85, 85, 85, 85]':
                                    result = u'零件号已写入'
                                    self.Recv_signal.emit(result)
                                else:
                                    result = u'零件号写入肯定响应回复错误'
                                    self.Recv_signal.emit(result)
                            if Response == '供应商名称':
                                if Data == 'Data=[3, 110, 241, 138, 85, 85, 85, 85]':
                                    result = u'供应商名称已写入'
                                    self.Recv_signal.emit(result)
                                else:
                                    result = u'供应商名称写入肯定响应回复错误'
                                    self.Recv_signal.emit(result)
                            if Response == 'ECU名称':
                                if Data == 'Data=[3, 110, 241, 151, 85, 85, 85, 85]':
                                    result = u'ECU名称已写入'
                                    self.Recv_signal.emit(result)
                                else:
                                    result = u'ECU名称写入肯定响应回复错误'
                                    self.Recv_signal.emit(result)
                            if Response == '硬件版本号':
                                if Data == 'Data=[3, 110, 241, 147, 85, 85, 85, 85]':
                                    result = u'硬件版本号已写入'
                                    self.Recv_signal.emit(result)
                                else:
                                    result = u'硬件版本号写入肯定响应回复错误'
                                    self.Recv_signal.emit(result)
                            if Response == '软件版本号':
                                if Data == 'Data=[3, 110, 241, 149, 85, 85, 85, 85]':
                                    result = u'软件版本号已写入'
                                    self.Recv_signal.emit(result)
                                else:
                                    result = u'软件版本号写入肯定响应回复错误'
                                    self.Recv_signal.emit(result)
                            if Response == 'ECU流水编号':
                                if Data == 'Data=[3, 110, 241, 140, 85, 85, 85, 85]':
                                    result = u'ECU流水编号已写入'
                                    self.Recv_signal.emit(result)
                                else:
                                    result = u'ECU流水编号写入肯定响应回复错误'
                                    self.Recv_signal.emit(result)
                        else:
                            Input0 = binascii.b2a_hex(InputMessage[0])
                            temp0 = '0x' + str(Input0)
                            Input1 = binascii.b2a_hex(InputMessage[1])
                            temp1 = '0x' + str(Input1)
                            Input2 = binascii.b2a_hex(InputMessage[2])
                            temp2 = '0x' + str(Input2)
                            Input3 = binascii.b2a_hex(InputMessage[3])
                            temp3 = '0x' + str(Input3)
                            data0 = int(temp0, 16)
                            data1 = int(temp1, 16)
                            data2 = int(temp2, 16)
                            data3 = int(temp3, 16)
                            if InputLen == 5:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                data4 = int(temp4, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x08, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x08, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x08, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x08, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x08, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x08, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x08, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
#                                print mess
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, 0x00, 0x00, 0x00, 0x00, 0x00]
#                                    print 'frame',frame
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 6:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x09, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x09, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x09, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x09, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x09, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x09, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x09, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, 0x00, 0x00, 0x00, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 7:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x0A, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x0A, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x0A, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x0A, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x0A, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x0A, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x0A, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, 0x00, 0x00, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 8:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x0B, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x0B, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x0B, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x0B, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x0B, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x0B, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x0B, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, 0x00, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 9:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                Input8 = binascii.b2a_hex(InputMessage[8])
                                temp8 = '0x' + str(Input8)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                data8 = int(temp8, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x0C, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x0C, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x0C, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x0C, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x0C, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x0C, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x0C, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, data8, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 10:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                Input8 = binascii.b2a_hex(InputMessage[8])
                                temp8 = '0x' + str(Input8)
                                Input9 = binascii.b2a_hex(InputMessage[9])
                                temp9 = '0x' + str(Input9)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                data8 = int(temp8, 16)
                                data9 = int(temp9, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x0D, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x0D, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x0D, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x0D, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x0D, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x0D, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x0D, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, data8, data9]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 11:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                Input8 = binascii.b2a_hex(InputMessage[8])
                                temp8 = '0x' + str(Input8)
                                Input9 = binascii.b2a_hex(InputMessage[9])
                                temp9 = '0x' + str(Input9)
                                Input10 = binascii.b2a_hex(InputMessage[10])
                                temp10 = '0x' + str(Input10)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                data8 = int(temp8, 16)
                                data9 = int(temp9, 16)
                                data10 = int(temp10, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x0E, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x0E, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x0E, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x0E, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x0E, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x0E, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x0E, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = datetime.datetime.now()
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, data8, data9]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                    frame.data = [0x22, data10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 12:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                Input8 = binascii.b2a_hex(InputMessage[8])
                                temp8 = '0x' + str(Input8)
                                Input9 = binascii.b2a_hex(InputMessage[9])
                                temp9 = '0x' + str(Input9)
                                Input10 = binascii.b2a_hex(InputMessage[10])
                                temp10 = '0x' + str(Input10)
                                Input11 = binascii.b2a_hex(InputMessage[11])
                                temp11 = '0x' + str(Input11)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                data8 = int(temp8, 16)
                                data9 = int(temp9, 16)
                                data10 = int(temp10, 16)
                                data11 = int(temp11, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x0F, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x0F, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x0F, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x0F, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x0F, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x0F, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x0F, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.n
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, data8, data9]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                    frame.data = [0x22, data10, data11, 0x00, 0x00, 0x00, 0x00, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 13:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                Input8 = binascii.b2a_hex(InputMessage[8])
                                temp8 = '0x' + str(Input8)
                                Input9 = binascii.b2a_hex(InputMessage[9])
                                temp9 = '0x' + str(Input9)
                                Input10 = binascii.b2a_hex(InputMessage[10])
                                temp10 = '0x' + str(Input10)
                                Input11 = binascii.b2a_hex(InputMessage[11])
                                temp11 = '0x' + str(Input11)
                                Input12 = binascii.b2a_hex(InputMessage[12])
                                temp12 = '0x' + str(Input12)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                data8 = int(temp8, 16)
                                data9 = int(temp9, 16)
                                data10 = int(temp10, 16)
                                data11 = int(temp11, 16)
                                data12 = int(temp12, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x10, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x10, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x10, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x10, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x10, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x10, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x10, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, data8, data9]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                    frame.data = [0x22, data10, data11, data12, 0x00, 0x00, 0x00, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 14:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                Input8 = binascii.b2a_hex(InputMessage[8])
                                temp8 = '0x' + str(Input8)
                                Input9 = binascii.b2a_hex(InputMessage[9])
                                temp9 = '0x' + str(Input9)
                                Input10 = binascii.b2a_hex(InputMessage[10])
                                temp10 = '0x' + str(Input10)
                                Input11 = binascii.b2a_hex(InputMessage[11])
                                temp11 = '0x' + str(Input11)
                                Input12 = binascii.b2a_hex(InputMessage[12])
                                temp12 = '0x' + str(Input12)
                                Input13 = binascii.b2a_hex(InputMessage[13])
                                temp13 = '0x' + str(Input13)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                data8 = int(temp8, 16)
                                data9 = int(temp9, 16)
                                data10 = int(temp10, 16)
                                data11 = int(temp11, 16)
                                data12 = int(temp12, 16)
                                data13 = int(temp13, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x11, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x11, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x11, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x11, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x11, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x11, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x11, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, data8, data9]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                    frame.data = [0x22, data10, data11, data12, data13, 0x00, 0x00, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 15:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                Input8 = binascii.b2a_hex(InputMessage[8])
                                temp8 = '0x' + str(Input8)
                                Input9 = binascii.b2a_hex(InputMessage[9])
                                temp9 = '0x' + str(Input9)
                                Input10 = binascii.b2a_hex(InputMessage[10])
                                temp10 = '0x' + str(Input10)
                                Input11 = binascii.b2a_hex(InputMessage[11])
                                temp11 = '0x' + str(Input11)
                                Input12 = binascii.b2a_hex(InputMessage[12])
                                temp12 = '0x' + str(Input12)
                                Input13 = binascii.b2a_hex(InputMessage[13])
                                temp13 = '0x' + str(Input13)
                                Input14 = binascii.b2a_hex(InputMessage[14])
                                temp14 = '0x' + str(Input14)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                data8 = int(temp8, 16)
                                data9 = int(temp9, 16)
                                data10 = int(temp10, 16)
                                data11 = int(temp11, 16)
                                data12 = int(temp12, 16)
                                data13 = int(temp13, 16)
                                data14 = int(temp14, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x12, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x12, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x12, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x12, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x12, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x12, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x12, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, data8, data9]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                    frame.data = [0x22, data10, data11, data12, data13, data14, 0x00, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 16:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                Input8 = binascii.b2a_hex(InputMessage[8])
                                temp8 = '0x' + str(Input8)
                                Input9 = binascii.b2a_hex(InputMessage[9])
                                temp9 = '0x' + str(Input9)
                                Input10 = binascii.b2a_hex(InputMessage[10])
                                temp10 = '0x' + str(Input10)
                                Input11 = binascii.b2a_hex(InputMessage[11])
                                temp11 = '0x' + str(Input11)
                                Input12 = binascii.b2a_hex(InputMessage[12])
                                temp12 = '0x' + str(Input12)
                                Input13 = binascii.b2a_hex(InputMessage[13])
                                temp13 = '0x' + str(Input13)
                                Input14 = binascii.b2a_hex(InputMessage[14])
                                temp14 = '0x' + str(Input14)
                                Input15 = binascii.b2a_hex(InputMessage[15])
                                temp15 = '0x' + str(Input15)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                data8 = int(temp8, 16)
                                data9 = int(temp9, 16)
                                data10 = int(temp10, 16)
                                data11 = int(temp11, 16)
                                data12 = int(temp12, 16)
                                data13 = int(temp13, 16)
                                data14 = int(temp14, 16)
                                data15 = int(temp15, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x13, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x13, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x13, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x13, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x13, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x13, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x13, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, data8, data9]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                    frame.data = [0x22, data10, data11, data12, data13, data14, data15, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 17:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                Input8 = binascii.b2a_hex(InputMessage[8])
                                temp8 = '0x' + str(Input8)
                                Input9 = binascii.b2a_hex(InputMessage[9])
                                temp9 = '0x' + str(Input9)
                                Input10 = binascii.b2a_hex(InputMessage[10])
                                temp10 = '0x' + str(Input10)
                                Input11 = binascii.b2a_hex(InputMessage[11])
                                temp11 = '0x' + str(Input11)
                                Input12 = binascii.b2a_hex(InputMessage[12])
                                temp12 = '0x' + str(Input12)
                                Input13 = binascii.b2a_hex(InputMessage[13])
                                temp13 = '0x' + str(Input13)
                                Input14 = binascii.b2a_hex(InputMessage[14])
                                temp14 = '0x' + str(Input14)
                                Input15 = binascii.b2a_hex(InputMessage[15])
                                temp15 = '0x' + str(Input15)
                                Input16 = binascii.b2a_hex(InputMessage[16])
                                temp16 = '0x' + str(Input16)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                data8 = int(temp8, 16)
                                data9 = int(temp9, 16)
                                data10 = int(temp10, 16)
                                data11 = int(temp11, 16)
                                data12 = int(temp12, 16)
                                data13 = int(temp13, 16)
                                data14 = int(temp14, 16)
                                data15 = int(temp15, 16)
                                data16 = int(temp16, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x14, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x14, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x14, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x14, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x14, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x14, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x14, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, data8, data9]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                    frame.data = [0x22, data10, data11, data12, data13, data14, data15, data16]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if InputLen == 18:
                                Input4 = binascii.b2a_hex(InputMessage[4])
                                temp4 = '0x' + str(Input4)
                                Input5 = binascii.b2a_hex(InputMessage[5])
                                temp5 = '0x' + str(Input5)
                                Input6 = binascii.b2a_hex(InputMessage[6])
                                temp6 = '0x' + str(Input6)
                                Input7 = binascii.b2a_hex(InputMessage[7])
                                temp7 = '0x' + str(Input7)
                                Input8 = binascii.b2a_hex(InputMessage[8])
                                temp8 = '0x' + str(Input8)
                                Input9 = binascii.b2a_hex(InputMessage[9])
                                temp9 = '0x' + str(Input9)
                                Input10 = binascii.b2a_hex(InputMessage[10])
                                temp10 = '0x' + str(Input10)
                                Input11 = binascii.b2a_hex(InputMessage[11])
                                temp11 = '0x' + str(Input11)
                                Input12 = binascii.b2a_hex(InputMessage[12])
                                temp12 = '0x' + str(Input12)
                                Input13 = binascii.b2a_hex(InputMessage[13])
                                temp13 = '0x' + str(Input13)
                                Input14 = binascii.b2a_hex(InputMessage[14])
                                temp14 = '0x' + str(Input14)
                                Input15 = binascii.b2a_hex(InputMessage[15])
                                temp15 = '0x' + str(Input15)
                                Input16 = binascii.b2a_hex(InputMessage[16])
                                temp16 = '0x' + str(Input16)
                                Input17 = binascii.b2a_hex(InputMessage[17])
                                temp17 = '0x' + str(Input17)
                                data4 = int(temp4, 16)
                                data5 = int(temp5, 16)
                                data6 = int(temp6, 16)
                                data7 = int(temp7, 16)
                                data8 = int(temp8, 16)
                                data9 = int(temp9, 16)
                                data10 = int(temp10, 16)
                                data11 = int(temp11, 16)
                                data12 = int(temp12, 16)
                                data13 = int(temp13, 16)
                                data14 = int(temp14, 16)
                                data15 = int(temp15, 16)
                                data16 = int(temp16, 16)
                                data17 = int(temp17, 16)
                                if Response == '车辆识别号':
                                    frame.data = [0x10, 0x15, 0x2E, 0xF1, 0x90, data0, data1, data2]
                                if Response == '零件号':
                                    frame.data = [0x10, 0x15, 0x2E, 0xF1, 0x87, data0, data1, data2]
                                if Response == '供应商名称':
                                    frame.data = [0x10, 0x15, 0x2E, 0xF1, 0x8A, data0, data1, data2]
                                if Response == 'ECU名称':
                                    frame.data = [0x10, 0x15, 0x2E, 0xF1, 0x97, data0, data1, data2]
                                if Response == '硬件版本号':
                                    frame.data = [0x10, 0x15, 0x2E, 0xF1, 0x93, data0, data1, data2]
                                if Response == '软件版本号':
                                    frame.data = [0x10, 0x15, 0x2E, 0xF1, 0x95, data0, data1, data2]
                                if Response == 'ECU流水编号':
                                    frame.data = [0x10, 0x15, 0x2E, 0xF1, 0x8C, data0, data1, data2]
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                self.Sender1_signal.emit(count, flag, str(frame))
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                    FCFlag = 1
                                    frame.data = [0x21, data3, data4, data5, data6, data7, data8, data9]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                    frame.data = [0x22, data10, data11, data12, data13, data14, data15, data16]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                    frame.data = [0x23, data17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                    dev.send(frame)
                                    self.Sender1_signal.emit(count, flag, str(frame))
                                else:
                                    result = u'HUD未回复流控帧'
                                    self.Recv_signal.emit(result)
                            if FCFlag == 1:
                                mess = dev.recv()
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if InputLen <= 8:
                                    if Response == '车辆识别号':
                                        if Data == 'Data=[3, 110, 241, 144, 85, 85, 85, 85]':
                                            result = u'车辆识别号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'车辆识别号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '零件号':
                                        if Data == 'Data=[3, 110, 241, 135, 85, 85, 85, 85]':
                                            result = u'零件号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'零件号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '供应商名称':
                                        if Data == 'Data=[3, 110, 241, 138, 85, 85, 85, 85]':
                                            result = u'供应商名称已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'供应商名称写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU名称':
                                        if Data == 'Data=[3, 110, 241, 151, 85, 85, 85, 85]':
                                            result = u'ECU名称已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU名称写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '硬件版本号':
                                        if Data == 'Data=[3, 110, 241, 147, 85, 85, 85, 85]':
                                            result = u'硬件版本号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'硬件版本号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '软件版本号':
                                        if Data == 'Data=[3, 110, 241, 149, 85, 85, 85, 85]':
                                            result = u'软件版本号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'软件版本号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU流水编号':
                                        if Data == 'Data=[3, 110, 241, 140, 85, 85, 85, 85]':
                                            result = u'ECU流水编号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU流水编号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                if InputLen > 8 and InputLen <= 10:
                                    if Response == '车辆识别号':
                                        if Data == 'Data=[3, 110, 241, 144, 85, 85, 85, 85]':
                                            result = u'车辆识别号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'车辆识别号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '零件号':
                                        if Data == 'Data=[3, 110, 241, 135, 85, 85, 85, 85]':
                                            result = u'零件号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'零件号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '供应商名称':
                                        if Data == 'Data=[3, 110, 241, 138, 85, 85, 85, 85]':
                                            result = u'供应商名称已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'供应商名称写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU名称':
                                        if Data == 'Data=[3, 110, 241, 151, 85, 85, 85, 85]':
                                            result = u'ECU名称已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU名称写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '硬件版本号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'硬件版本号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'硬件版本号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '软件版本号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'软件版本号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'软件版本号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU流水编号':
                                        if Data == 'Data=[3, 110, 241, 140, 85, 85, 85, 85]':
                                            result = u'ECU流水号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU流水号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                if InputLen > 10 and InputLen <= 12:
                                    if Response == '车辆识别号':
                                        if Data == 'Data=[3, 110, 241, 144, 85, 85, 85, 85]':
                                            result = u'车辆识别号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'车辆识别号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '零件号':
                                        if Data == 'Data=[3, 110, 241, 135, 85, 85, 85, 85]':
                                            result = u'零件号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'零件号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '供应商名称':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'供应商名称输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'供应商名称输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU名称':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'ECU名称输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU名称输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '硬件版本号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'硬件版本号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'硬件版本号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '软件版本号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'软件版本号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'软件版本号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU流水编号':
                                        if Data == 'Data=[3, 110, 241, 140, 85, 85, 85, 85]':
                                            result = u'ECU流水号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU流水号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                if InputLen > 12 and InputLen <= 14:
                                    if Response == '车辆识别号':
                                        if Data == 'Data=[3, 110, 241, 144, 85, 85, 85, 85]':
                                            result = u'车辆识别号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'车辆识别号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '零件号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'零件号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'零件号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '供应商名称':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'供应商名称输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'供应商名称输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU名称':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'ECU名称输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU名称输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '硬件版本号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'硬件版本号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'硬件版本号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '软件版本号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'软件版本号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'软件版本号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU流水编号':
                                        if Data == 'Data=[3, 110, 241, 140, 85, 85, 85, 85]':
                                            result = u'ECU流水号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU流水号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                if InputLen > 14 and InputLen <= 17:
                                    if Response == '车辆识别号':
                                        if Data == 'Data=[3, 110, 241, 144, 85, 85, 85, 85]':
                                            result = u'车辆识别号已写入'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'车辆识别号写入肯定响应回复错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '零件号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'零件号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'零件号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '供应商名称':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'供应商名称输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'供应商名称输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU名称':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'ECU名称输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU名称输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '硬件版本号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'硬件版本号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'硬件版本号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '软件版本号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'软件版本号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'软件版本号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU流水编号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'ECU流水号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU流水号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                if InputLen > 17:
                                    if Response == '车辆识别号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'车辆识别号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'车辆识别号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '零件号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'零件号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'零件号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '供应商名称':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'供应商名称输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'供应商名称输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU名称':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'ECU名称输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU名称输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '硬件版本号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'硬件版本号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'硬件版本号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == '软件版本号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'软件版本号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'软件版本号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                    if Response == 'ECU流水编号':
                                        if Data == 'Data=[3, 127, 46, 19, 85, 85, 85, 85]':
                                            result = u'ECU流水号输入值超过最大值，HUD已拒绝写入，请输入合法值'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'ECU流水号输入值超过最大值，HUD未做出否定响应，响应错误'
                                            self.Recv_signal.emit(result)
                                else:
                                    pass
                    else:
                        result = u'HUD未回复密钥响应'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)


class Send2(QtCore.QThread):
    Sender2_signal = QtCore.pyqtSignal(int, int, str)
    Recv_signal = QtCore.pyqtSignal(str)
    Result_signal = QtCore.pyqtSignal(int)
    ResponseResult = QtCore.pyqtSignal(int)
    TimeSignal = QtCore.pyqtSignal(str)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        count = 1
        flag = 1
        if UnSer == '电控单元复位':
            if UnResponse == '子功能不支持':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x11, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 17, 18, 85, 85, 85, 85]':
                    result = u'子功能不支持，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'子功能不支持，系统响应错误'
                    self.Recv_signal.emit(result)

            if UnResponse == '报文长度错误':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x03, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 17, 19, 85, 85, 85, 85]':
                    result = u'报文长度错误，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'报文长度错误，系统响应错误'
                    self.Recv_signal.emit(result)

        if UnSer == '诊断设备在线':
            if UnResponse == '子功能不支持':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 62, 18, 85, 85, 85, 85]':
                    result = u'子功能不支持，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'子功能不支持，系统响应错误'
                    self.Recv_signal.emit(result)

            if UnResponse == '报文长度错误':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x03, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 62, 19, 85, 85, 85, 85]':
                    result = u'报文长度错误，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'报文长度错误，系统响应错误'
                    self.Recv_signal.emit(result)

        if UnSer == '清除诊断信息':
            if UnResponse == '报文长度错误':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x05, 0x14, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 20, 19, 85, 85, 85, 85]':
                    result = u'报文长度错误，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'报文长度错误，系统响应错误'
                    self.Recv_signal.emit(result)

            if UnResponse == '请求超出范围':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x04, 0x14, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 20, 49, 85, 85, 85, 85]':
                    result = u'请求超出范围，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'请求超出范围，系统响应错误'
                    self.Recv_signal.emit(result)

        if UnSer == '安全访问-种子':
            if UnResponse == '子功能不支持':
                frame = can.Frame(CanID)
                frame.dlc = 3
                dev.start()
                frame.data = [0x02, 0x27, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 39, 18, 85, 85, 85, 85]':
                    result = u'子功能不支持，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'子功能不支持，系统响应错误'
                    self.Recv_signal.emit(result)

            if UnResponse == '报文长度错误':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x04, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 39, 19, 85, 85, 85, 85]':
                    result = u'报文长度错误，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'报文长度错误，系统响应错误'
                    self.Recv_signal.emit(result)

        # if UnSer == '安全访问-密钥':
        #     if UnResponse == '子功能不支持':
        #         frame = can.Frame(CanID)
        #         frame.dlc = 3
        #         dev.start()
        #         frame.data = [0x02, 0x27, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
        #         self.Sender2_signal.emit(count, flag, str(frame))
        #         dev.send(frame)
        #         timeStart = datetime.datetime.now()
        #         mess = dev.recv()
        #         timeEnd = datetime.datetime.now()
        #         timeSleep = timeEnd - timeStart
        #         self.TimeSignal.emit(str(timeSleep))
        #         Mess = str(mess)
        #         new = Mess.split('\n')
        #         final = new[0] + new[1]
        #         self.Recv_signal.emit(final)
        #         Pattern_Data = re.compile(r'Data=.+')
        #         DataGroup = Pattern_Data.search(Mess)
        #         Data = DataGroup.group()
        #         if Data == 'Data=[3, 127, 39, 18, 85, 85, 85, 85]':
        #             result = u'子功能不支持，系统响应正确'
        #             self.Recv_signal.emit(result)
        #         else:
        #             result = u'子功能不支持，系统响应错误'
        #             self.Recv_signal.emit(result)

            # if UnResponse == '报文长度错误':
            #     frame = can.Frame(CanID)
            #     frame.dlc = 8
            #     dev.start()
            #     frame.data = [0x04, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
            #     self.Sender2_signal.emit(count, flag, str(frame))
            #     dev.send(frame)
            #     timeStart = datetime.datetime.now()
            #     mess = dev.recv()
            #     timeEnd = datetime.datetime.now()
            #     timeSleep = timeEnd - timeStart
            #     self.TimeSignal.emit(str(timeSleep))
            #     Mess = str(mess)
            #     new = Mess.split('\n')
            #     final = new[0] + new[1]
            #     self.Recv_signal.emit(final)
            #     Pattern_Data = re.compile(r'Data=.+')
            #     DataGroup = Pattern_Data.search(Mess)
            #     Data = DataGroup.group()
            #     if Data == 'Data=[3, 127, 39, 19, 85, 85, 85, 85]':
            #         result = u'报文长度错误，系统响应正确'
            #         self.Recv_signal.emit(result)
            #     else:
            #         result = u'报文长度错误，系统响应错误'
            #         self.Recv_signal.emit(result)

        if UnSer == '通信控制':
            if UnResponse == '子功能不支持':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x28, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 40, 18, 85, 85, 85, 85]':
                    result = u'子功能不支持，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'子功能不支持，系统响应错误'
                    self.Recv_signal.emit(result)

            if UnResponse == '报文长度错误':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x04, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 40, 19, 85, 85, 85, 85]':
                    result = u'报文长度错误，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'报文长度错误，系统响应错误'
                    self.Recv_signal.emit(result)

            if UnResponse == '请求超出范围':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x28, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 40, 49, 85, 85, 85, 85]':
                    result = u'请求超出范围，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'请求超出范围，系统响应错误'
                    self.Recv_signal.emit(result)

        if UnSer == '控制DTC设置':
            if UnResponse == '子功能不支持':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x02, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 133, 18, 85, 85, 85, 85]':
                    result = u'子功能不支持，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'子功能不支持，系统响应错误'
                    self.Recv_signal.emit(result)

            if UnResponse == '报文长度错误':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x85, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 133, 19, 85, 85, 85, 85]':
                    result = u'报文长度错误，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'报文长度错误，系统响应错误'
                    self.Recv_signal.emit(result)

        if UnSer == '读取DTC数量':
            if UnResponse == '子功能不支持':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x19, 0x03, 0x09, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 25, 18, 85, 85, 85, 85]':
                    result = u'子功能不支持，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'子功能不支持，系统响应错误'
                    self.Recv_signal.emit(result)

            if UnResponse == '报文长度错误':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x04, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 25, 19, 85, 85, 85, 85]':
                    result = u'报文长度错误，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'报文长度错误，系统响应错误'
                    self.Recv_signal.emit(result)

            if UnResponse == '请求超出范围':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x19, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_Data = re.compile(r'Data=.+')
                DataGroup = Pattern_Data.search(Mess)
                Data = DataGroup.group()
                if Data == 'Data=[3, 127, 25, 49, 85, 85, 85, 85]':
                    result = u'请求超出范围，系统响应正确'
                    self.Recv_signal.emit(result)
                else:
                    result = u'请求超出范围，系统响应错误'
                    self.Recv_signal.emit(result)

        if UnSer == '读取DTC':
            if UnResponse == '子功能不支持':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x19, 0x03, 0x09, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 25, 18, 85, 85, 85, 85]':
                        result = u'子功能不支持，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'子功能不支持，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

            if UnResponse == '报文长度错误':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x04, 0x19, 0x02, 0x09, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 25, 19, 85, 85, 85, 85]':
                        result = u'报文长度错误，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'报文长度错误，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

            if UnResponse == '请求超出范围':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x19, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 25, 49, 85, 85, 85, 85]':
                        result = u'请求超出范围，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'请求超出范围，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if UnSer == '读取数据':
            if UnResponse == '报文长度错误':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x04, 0x22, 0xF1, 0x90, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 34, 19, 85, 85, 85, 85]':
                        result = u'报文长度错误，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'报文长度错误，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

            if UnResponse == '请求超出范围':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x22, 0xF1, 0x88, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 34, 49, 85, 85, 85, 85]':
                        result = u'请求超出范围，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'请求超出范围，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if UnSer == '写入数据':
            frame = can.Frame(CanID)
            frame.dlc = 8
            dev.start()
            if UnResponse == '安全访问拒绝':
                frame.data = [0x10, 0x0B, 0x2E, 0xF1, 0x93, 0x56, 0x31, 0x2E]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                        frame.data = [0x21, 0x31, 0x2E, 0x32, 0x2E, 0x33, 0x00, 0x00]
                        self.Sender2_signal.emit(count, flag, str(frame))
                        dev.send(frame)
                        timeStart = datetime.datetime.now()
                        mess = dev.recv()
                        timeEnd = datetime.datetime.now()
                        timeSleep = timeEnd - timeStart
                        self.TimeSignal.emit(str(timeSleep))
                        while (mess.id != 1961):
                            mess = dev.recv()
                        Mess = str(mess)
                        new = Mess.split('\n')
                        final = new[0] + new[1]
                        self.Recv_signal.emit(final)
                        Pattern_id = re.compile(r'ID=0x7A9,')
                        Match = Pattern_id.search(Mess)
                        if Match:
                            Pattern_Data = re.compile(r'Data=.+')
                            DataGroup = Pattern_Data.search(Mess)
                            Data = DataGroup.group()
                            if Data == 'Data=[3, 127, 46, 51, 85, 85, 85, 85]':
                                result = u'安全访问拒绝，系统响应正确'
                                self.Recv_signal.emit(result)
                            else:
                                result = u'安全访问拒绝，系统响应错误,检查系统是否曾经获得过认证权限，如果权限已经获得，复位后直接测试此项'
                                self.Recv_signal.emit(result)
                        else:
                            self.Result_signal.emit(0)
                    else:
                        result = u'HUD回复流控帧错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)
            else:
                frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender2_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    frame.data = [0x06, 0x27, 0x02, 0x00, 0x11, 0x22, 0x33, 0x00]
                    dev.send(frame)
                    timeStart = datetime.datetime.now()
                    self.Sender2_signal.emit(count, flag, str(frame))
                    mess = dev.recv()
                    timeEnd = datetime.datetime.now()
                    timeSleep = timeEnd - timeStart
                    self.TimeSignal.emit(str(timeSleep))
                    Mess = str(mess)
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Match:
                        if Data == 'Data=[2, 103, 2, 85, 85, 85, 85, 85]':
                            if UnResponse == '请求超出范围':
                                frame.data = [0x10, 0x0B, 0x2E, 0xF1, 0x88, 0x56, 0x31, 0x2E]
                                self.Sender2_signal.emit(count, flag, str(frame))
                                dev.send(frame)
                                timeStart = datetime.datetime.now()
                                mess = dev.recv()
                                timeEnd = datetime.datetime.now()
                                timeSleep = timeEnd - timeStart
                                self.TimeSignal.emit(str(timeSleep))
                                Mess = str(mess)
                                new = Mess.split('\n')
                                final = new[0] + new[1]
                                self.Recv_signal.emit(final)
                                Pattern_id = re.compile(r'ID=0x7A9,')
                                Match = Pattern_id.search(Mess)
                                if Match:
                                    Pattern_Data = re.compile(r'Data=.+')
                                    DataGroup = Pattern_Data.search(Mess)
                                    Data = DataGroup.group()
                                    if Data == 'Data=[48, 10, 100, 85, 85, 85, 85, 85]':
                                        frame.data = [0x21, 0x31, 0x2E, 0x32, 0x2E, 0x33, 0x00, 0x00]
                                        self.Sender2_signal.emit(count, flag, str(frame))
                                        dev.send(frame)
                                        timeStart = datetime.datetime.now()
                                        mess = dev.recv()
                                        timeEnd = datetime.datetime.now()
                                        timeSleep = timeEnd - timeStart
                                        self.TimeSignal.emit(str(timeSleep))
                                        Mess = str(mess)
                                        new = Mess.split('\n')
                                        final = new[0] + new[1]
                                        self.Recv_signal.emit(final)
                                        Pattern_id = re.compile(r'ID=0x7A9,')
                                        Match = Pattern_id.search(Mess)
                                        if Match:
                                            Pattern_Data = re.compile(r'Data=.+')
                                            DataGroup = Pattern_Data.search(Mess)
                                            Data = DataGroup.group()
                                            if Data == 'Data=[3, 127, 46, 49, 85, 85, 85, 85]':
                                                result = u'请求超出范围，系统响应正确'
                                                self.Recv_signal.emit(result)
                                            else:
                                                result = u'请求超出范围，系统响应错误'
                                                self.Recv_signal.emit(result)
                                    else:
                                        result = u'HUD未回复正确流控帧！'
                                        self.Recv_signal.emit(result)
                        else:
                            result = u'系统回复种子肯定响应码错误！'
                            self.Recv_signal.emit(result)
                    else:
                        self.Result_signal.emit(0)


class Send3(QtCore.QThread):
    Sender3_signal = QtCore.pyqtSignal(int, int, str)
    Recv_signal = QtCore.pyqtSignal(str)
    Result_signal = QtCore.pyqtSignal(int)
    ResponseResult = QtCore.pyqtSignal(int)
    TimeSignal = QtCore.pyqtSignal(str)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        count = 1
        flag = 1
        if UnSpSer == '电控单元复位':
            if UnSpResponse == '条件未满足':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x02, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender3_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 17, 34, 85, 85, 85, 85]':
                        result = u'条件未满足，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'条件未满足，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if UnSpSer == '清除诊断信息':
            if UnSpResponse == '条件未满足':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x04, 0x14, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender3_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 20, 34, 85, 85, 85, 85]':
                        result = u'条件未满足，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'条件未满足，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if UnSpSer == '安全访问-种子':
            if UnSpResponse == '条件未满足':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender3_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 39, 34, 85, 85, 85, 85]':
                        result = u'条件未满足，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'条件未满足，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)
        '''
        if UnSpSer == '安全访问-密钥':
            if UnSpResponse == '条件未满足':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x02, 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender3_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 39, 34, 85, 85, 85, 85]':
                        result = u'条件未满足，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'条件未满足，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)
                '''

        if UnSpSer == '通信控制':
            if UnSpResponse == '条件未满足':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x28, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00]
                self.Sender3_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 40, 34, 85, 85, 85, 85]':
                        result = u'条件未满足，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'条件未满足，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if UnSpSer == '控制DTC设置':
            if UnSpResponse == '条件未满足':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x02, 0x85, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender3_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 133, 34, 85, 85, 85, 85]':
                        result = u'条件未满足，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'条件未满足，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if UnSpSer == '写入数据':
            if UnSpResponse == '条件未满足':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                self.Sender3_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 39, 34, 85, 85, 85, 85]':
                        result = u'条件未满足，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'条件未满足，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)
            if UnSpResponse == '安全访问拒绝':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x07, 0x2E, 0xF1, 0x90, 0x31, 0x32, 0x33, 0x34]
                self.Sender3_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 46, 51, 85, 85, 85, 85]':
                        result = u'安全访问拒绝，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'安全访问拒绝，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if UnSpSer == '读取DTC数量':
            if UnSpResponse == '条件未满足':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                self.Sender3_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 25, 34, 85, 85, 85, 85]':
                        result = u'条件未满足，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'条件未满足，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)

        if UnSpSer == '读取DTC':
            if UnSpResponse == '条件未满足':
                frame = can.Frame(CanID)
                frame.dlc = 8
                dev.start()
                frame.data = [0x03, 0x19, 0x02, 0x09, 0x00, 0x00, 0x00, 0x00]
                self.Sender3_signal.emit(count, flag, str(frame))
                dev.send(frame)
                timeStart = datetime.datetime.now()
                mess = dev.recv()
                timeEnd = datetime.datetime.now()
                timeSleep = timeEnd - timeStart
                self.TimeSignal.emit(str(timeSleep))
                Mess = str(mess)
                new = Mess.split('\n')
                final = new[0] + new[1]
                self.Recv_signal.emit(final)
                Pattern_id = re.compile(r'ID=0x7A9,')
                Match = Pattern_id.search(Mess)
                if Match:
                    Pattern_Data = re.compile(r'Data=.+')
                    DataGroup = Pattern_Data.search(Mess)
                    Data = DataGroup.group()
                    if Data == 'Data=[3, 127, 25, 34, 85, 85, 85, 85]':
                        result = u'条件未满足，系统响应正确'
                        self.Recv_signal.emit(result)
                    else:
                        result = u'条件未满足，系统响应错误'
                        self.Recv_signal.emit(result)
                else:
                    self.Result_signal.emit(0)


class Monkey(QtCore.QThread):
    Sender_signal = QtCore.pyqtSignal(int, int, str)
    Recv_signal = QtCore.pyqtSignal(str)
    Monkey_signal = QtCore.pyqtSignal(int)
    BadMonkey_signal = QtCore.pyqtSignal(int)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        global ResetFlag  # 0 default model,1 progrom,2 extend
        frame = can.Frame(CanID)
        frame.dlc = 8
        frame.data = [0x02, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
        dev.start()
        dev.send(frame)
        temp = dev.recv()
        time.sleep(7)
        ResetFlag = 0
        Flag = 0
        BadMonkey = 0
        for count in range(1, MonkeyCount + 1):
            self.Monkey_signal.emit(count)
            ModelFlag = random.randint(0, 2)
            Response = random.randint(0, 6)
            if Flag == 0:
                if ModelFlag == 0:
                    frame.data = [0x02, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                    self.Sender_signal.emit(count, 1, str(frame))
                    dev.send(frame)
                    Mess = str(dev.recv())
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[6, 80, 1, 0, 50, 1, 244, 85]':
                            result = u'默认切换默认，系统响应正确'
                            self.Recv_signal.emit(result)
                            if Response == 0:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x11, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 1:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x04, 0x14, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x04, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x05, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x14, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 2:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x03, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x03, 0x19, 0x03, 0x09, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x04, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x19, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00]
                            if Response == 3:
                                frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 4:
                                frame.data = [0x03, 0x28, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00]
                            if Response == 5:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 6:
                                frame.data = [0x02, 0x85, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                            self.Sender_signal.emit(count, 1, str(frame))
                            dev.send(frame)
                            Mess = str(dev.recv())
                            new = Mess.split('\n')
                            final = new[0] + new[1]
                            self.Recv_signal.emit(final)
                            Pattern_id = re.compile(r'ID=0x7A9,')
                            Match = Pattern_id.search(Mess)
                            if Match:
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Response == 0:
                                    if Action == 0:
                                        if Data == 'Data=[2, 81, 3, 85, 85, 85, 85, 85]':
                                            result = u'默认-软件复位，系统响应正确'
                                            self.Recv_signal.emit(result)
                                            time.sleep(5)
                                        else:
                                            result = u'默认-软件复位，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 17, 18, 85, 85, 85, 85]':
                                            result = u'默认-ECUReset-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-ECUReset-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 17, 19, 85, 85, 85, 85]':
                                            result = u'默认-ECUReset-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-ECUReset-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 1:
                                    if Action == 0:
                                        if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                                            result = u'默认-清除HUD诊断信息，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-清除HUD诊断信息，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                                            result = u'默认-清除所有组诊断信息，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-清除所有组诊断信息，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 20, 19, 85, 85, 85, 85]':
                                            result = u'默认-清除诊断-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-清除诊断-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 20, 49, 85, 85, 85, 85]':
                                            result = u'默认-清除诊断-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-清除诊断-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 2:
                                    if Action == 0:
                                        if Data == 'Data=[6, 89, 1, 9, 1, 0, 1, 85]':
                                            result = u'默认-读取DTC数量，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-读取DTC数量，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 25, 18, 85, 85, 85, 85]':
                                            result = u'默认-读取DTC-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-读取DTC-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 25, 19, 85, 85, 85, 85]':
                                            result = u'默认-读取DTC-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-读取DTC-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 25, 49, 85, 85, 85, 85]':
                                            result = u'默认-读取DTC-请求超出范围，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-读取DTC-请求超出范围，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 5:
                                    if Action == 0:
                                        if Data == 'Data=[2, 126, 0, 85, 85, 85, 85, 85]':
                                            result = u'默认-诊断设备在线，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-诊断设备在线，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 62, 18, 85, 85, 85, 85]':
                                            result = u'默认-诊断设备在线-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-诊断设备在线-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 62, 19, 85, 85, 85, 85]':
                                            result = u'默认-诊断设备在线-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认-诊断设备在线-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 3:
                                    if Data == 'Data=[3, 127, 39, 34, 85, 85, 85, 85]':
                                        result = u'默认-安全访问-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'默认-安全访问-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 4:
                                    if Data == 'Data=[3, 127, 40, 34, 85, 85, 85, 85]':
                                        result = u'默认-通信控制-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'默认-通信控制-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 6:
                                    if Data == 'Data=[3, 127, 133, 34, 85, 85, 85, 85]':
                                        result = u'默认-控制DTC设置-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'默认-控制DTC设置-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                            else:
                                result = u'系统响应帧ID不对'
                                self.Recv_signal.emit(result)
                                BadMonkey += 1
                                self.BadMonkey_signal.emit(BadMonkey)
                        else:
                            result = u'默认切换默认，系统响应错误'
                            self.Recv_signal.emit(result)
                            BadMonkey += 1
                            self.BadMonkey_signal.emit(BadMonkey)
                    else:
                        result = u'系统回复的CAN ID不是0x7A9'
                        self.Recv_signal.emit(result)
                        BadMonkey += 1
                        self.BadMonkey_signal.emit(BadMonkey)
                elif ModelFlag == 1:
                    frame.data = [0x02, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                    self.Sender_signal.emit(count, 1, str(frame))
                    dev.send(frame)
                    Mess = str(dev.recv())
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[3, 127, 16, 34, 85, 85, 85, 85]':
                            result = u'默认切换编程，条件未满足，系统响应正确'
                            self.Recv_signal.emit(result)
                        else:
                            result = u'默认切换编程，条件未满足，系统响应错误'
                            self.Recv_signal.emit(result)
                            BadMonkey += 1
                            self.BadMonkey_signal.emit(BadMonkey)
                    else:
                        result = u'系统响应帧ID不对'
                        self.Recv_signal.emit(result)
                        BadMonkey += 1
                        self.BadMonkey_signal.emit(BadMonkey)
                else:
                    frame.data = [0x02, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                    self.Sender_signal.emit(count, 1, str(frame))
                    dev.send(frame)
                    Mess = str(dev.recv())
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[6, 80, 3, 0, 50, 1, 244, 85]':
                            result = u'默认切换扩展，系统响应正确'
                            self.Recv_signal.emit(result)
                            Flag = 2
                            if Response == 0:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x11, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 1:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x04, 0x14, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x04, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x05, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x14, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 2:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x03, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x03, 0x19, 0x03, 0x09, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x04, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x19, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00]
                            if Response == 3:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x27, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 4:
                                Action = random.randint(0, 6)
                                if Action == 0:
                                    frame.data = [0x03, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x03, 0x28, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x03, 0x28, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 3:
                                    frame.data = [0x03, 0x28, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 4:
                                    frame.data = [0x03, 0x28, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 5:
                                    frame.data = [0x04, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x28, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00]
                            if Response == 5:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 6:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x02, 0x85, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x02, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                            self.Sender_signal.emit(count, 1, str(frame))
                            dev.send(frame)
                            Mess = str(dev.recv())
                            new = Mess.split('\n')
                            final = new[0] + new[1]
                            self.Recv_signal.emit(final)
                            Pattern_id = re.compile(r'ID=0x7A9,')
                            Match = Pattern_id.search(Mess)
                            if Match:
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Response == 0:
                                    if Action == 0:
                                        if Data == 'Data=[2, 81, 3, 85, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-软件复位，系统响应正确'
                                            self.Recv_signal.emit(result)
                                            Flag = 0
                                            time.sleep(5)
                                        else:
                                            result = u'默认切换扩展-软件复位，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 17, 18, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-ECUReset-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-ECUReset-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 17, 19, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-ECUReset-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-ECUReset-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 1:
                                    if Action == 0:
                                        if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-清除HUD诊断信息，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-清除HUD诊断信息，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-清除所有组诊断信息，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-清除所有组诊断信息，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 20, 19, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-清除诊断信息-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-清除诊断信息-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 20, 49, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-清除诊断信息-请求超出范围，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-清除诊断信息-请求超出范围，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 2:
                                    if Action == 0:
                                        if Data == 'Data=[6, 89, 1, 9, 1, 0, 1, 85]':
                                            result = u'默认切换扩展-读取DTC数量，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-读取DTC数量，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 25, 18, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-读取DTC-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-读取DTC-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 25, 19, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-读取DTC-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-读取DTC-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 25, 49, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-读取DTC-请求超出范围，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-读取DTC-请求超出范围，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 3:
                                    if Action == 0:
                                        if Data:#== 'Data=[6, 103, 1, 0, 17, 34, 51, 85]':
                                            result = u'默认切换扩展-安全访问，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-安全访问，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 39, 18, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-安全访问-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-安全访问-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 39, 19, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-安全访问-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-安全访问-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 4:
                                    if Action == 0:
                                        if Data == 'Data=[2, 104, 0, 85, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-通信控制-使能接收和发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-通信控制-使能接收和发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[2, 104, 1, 85, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-通信控制-使能接收且禁止发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-通信控制-使能接收且禁止发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[2, 104, 2, 85, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-通信控制-禁止接收且使能发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-通信控制-禁止接收且使能发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 3:
                                        if Data == 'Data=[2, 104, 3, 85, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-通信控制-禁止接收且禁止发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-通信控制-禁止接收且禁止发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 4:
                                        if Data == 'Data=[3, 127, 40, 18, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-通信控制-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-通信控制-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 5:
                                        if Data == 'Data=[3, 127, 40, 19, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-通信控制-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-通信控制-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 40, 49, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-通信控制-请求超出范围，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-通信控制-请求超出范围，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 5:
                                    if Action == 0:
                                        if Data == 'Data=[2, 126, 0, 85, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-诊断设备在线，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-诊断设备在线，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 62, 18, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-诊断设备在线-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-诊断设备在线-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 62, 19, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-诊断设备在线-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-诊断设备在线-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 6:
                                    if Action == 0:
                                        if Data == 'Data=[2, 197, 1, 85, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-打开DTC设置，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-打开DTC设置，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[2, 197, 2, 85, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-关闭DTC设置，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-关闭DTC设置，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 133, 18, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-DTC设置-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-DTC设置-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 133, 19, 85, 85, 85, 85]':
                                            result = u'默认切换扩展-DTC设置-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'默认切换扩展-DTC设置-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                        else:
                            result = u'默认切换扩展，系统响应错误'
                            self.Recv_signal.emit(result)
                            BadMonkey += 1
                            self.BadMonkey_signal.emit(BadMonkey)
                            Flag = 0
                    else:
                        result = u'系统响应帧ID不对'
                        self.Recv_signal.emit(result)
                        BadMonkey += 1
                        self.BadMonkey_signal.emit(BadMonkey)
                        Flag = 0
            elif Flag == 1:
                if ModelFlag == 0:
                    frame.data = [0x02, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                    self.Sender_signal.emit(count, 1, str(frame))
                    dev.send(frame)
                    Mess = str(dev.recv())
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[6, 80, 1, 0, 50, 1, 244, 85]':
                            result = u'编程切换默认，系统响应正确'
                            self.Recv_signal.emit(result)
                            Flag = 0
                            if Response == 0:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x11, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 1:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x04, 0x14, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x04, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x05, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x14, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 2:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x03, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x03, 0x19, 0x03, 0x09, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x04, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x19, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00]
                            if Response == 3:
                                frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 4:
                                frame.data = [0x03, 0x28, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00]
                            if Response == 5:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 6:
                                frame.data = [0x02, 0x85, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                            self.Sender_signal.emit(count, 1, str(frame))
                            dev.send(frame)
                            Mess = str(dev.recv())
                            new = Mess.split('\n')
                            final = new[0] + new[1]
                            self.Recv_signal.emit(final)
                            Pattern_id = re.compile(r'ID=0x7A9,')
                            Match = Pattern_id.search(Mess)
                            if Match:
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Response == 0:
                                    if Action == 0:
                                        if Data == 'Data=[2, 81, 3, 85, 85, 85, 85, 85]':
                                            result = u'编程切换默认-软件复位，系统响应正确'
                                            self.Recv_signal.emit(result)
                                            Flag = 0
                                            time.sleep(5)
                                        else:
                                            result = u'编程切换默认-软件复位，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 17, 18, 85, 85, 85, 85]':
                                            result = u'编程切换默认-ECUReset-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-ECUReset-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 17, 19, 85, 85, 85, 85]':
                                            result = u'编程切换默认-ECUReset-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-ECUReset-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 1:
                                    if Action == 0:
                                        if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                                            result = u'编程切换默认-清除HUD诊断信息，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-清除HUD诊断信息，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                                            result = u'编程切换默认-清除所有组诊断信息，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-清除所有组诊断信息，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 20, 19, 85, 85, 85, 85]':
                                            result = u'编程切换默认-清除诊断-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-清除诊断-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 20, 49, 85, 85, 85, 85]':
                                            result = u'编程切换默认-清除诊断-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-清除诊断-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 2:
                                    if Action == 0:
                                        if Data == 'Data=[6, 89, 1, 9, 1, 0, 1, 85]':
                                            result = u'编程切换默认-读取DTC数量，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-读取DTC数量，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 25, 18, 85, 85, 85, 85]':
                                            result = u'编程切换默认-读取DTC-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-读取DTC-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 25, 19, 85, 85, 85, 85]':
                                            result = u'编程切换默认-读取DTC-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-读取DTC-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 25, 49, 85, 85, 85, 85]':
                                            result = u'编程切换默认-读取DTC-请求超出范围，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-读取DTC-请求超出范围，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 5:
                                    if Action == 0:
                                        if Data == 'Data=[2, 126, 0, 85, 85, 85, 85, 85]':
                                            result = u'编程切换默认-诊断设备在线，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-诊断设备在线，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 62, 18, 85, 85, 85, 85]':
                                            result = u'编程切换默认-诊断设备在线-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-诊断设备在线-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 62, 19, 85, 85, 85, 85]':
                                            result = u'编程切换默认-诊断设备在线-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程切换默认-诊断设备在线-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 3:
                                    if Data == 'Data=[3, 127, 39, 34, 85, 85, 85, 85]':
                                        result = u'编程切换默认后，安全访问-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'编程切换默认后，安全访问-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 4:
                                    if Data == 'Data=[3, 127, 40, 34, 85, 85, 85, 85]':
                                        result = u'编程切换默认后，通信控制-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'编程切换默认后，通信控制-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 6:
                                    if Data == 'Data=[3, 127, 133, 34, 85, 85, 85, 85]':
                                        result = u'编程切换默认后，控制DTC设置-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'编程切换默认后，控制DTC设置-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                        else:
                            result = u'编程切换默认，系统响应错误'
                            self.Recv_signal.emit(result)
                            BadMonkey += 1
                            self.BadMonkey_signal.emit(BadMonkey)
                            Flag = 1
                    else:
                        result = u'系统响应帧ID不对'
                        self.Recv_signal.emit(result)
                        BadMonkey += 1
                        self.BadMonkey_signal.emit(BadMonkey)
                        Flag = 1
                if ModelFlag == 1:
                    frame.data = [0x02, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                    self.Sender_signal.emit(count, 1, str(frame))
                    dev.send(frame)
                    Mess = str(dev.recv())
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[6, 80, 2, 0, 50, 1, 244, 85]':
                            result = u'编程切换编程，系统响应正确'
                            self.Recv_signal.emit(result)
                            if Response == 0:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x11, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 1:
                                frame.data = [0x04, 0x14, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 2:
                                frame.data = [0x03, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                            if Response == 3:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x27, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 4:
                                Action = random.randint(0, 6)
                                if Action == 0:
                                    frame.data = [0x03, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x03, 0x28, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x03, 0x28, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 3:
                                    frame.data = [0x03, 0x28, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 4:
                                    frame.data = [0x03, 0x28, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 5:
                                    frame.data = [0x04, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x28, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00]
                            if Response == 5:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 6:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x02, 0x85, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x02, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                            self.Sender_signal.emit(count, 1, str(frame))
                            dev.send(frame)
                            Mess = str(dev.recv())
                            new = Mess.split('\n')
                            final = new[0] + new[1]
                            self.Recv_signal.emit(final)
                            Pattern_id = re.compile(r'ID=0x7A9,')
                            Match = Pattern_id.search(Mess)
                            if Match:
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Response == 0:
                                    if Action == 0:
                                        if Data == 'Data=[2, 81, 3, 85, 85, 85, 85, 85]':
                                            result = u'编程-软件复位，系统响应正确'
                                            self.Recv_signal.emit(result)
                                            Flag = 0
                                            time.sleep(5)
                                        else:
                                            result = u'编程-软件复位，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 17, 18, 85, 85, 85, 85]':
                                            result = u'编程-ECUReset-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-ECUReset-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 17, 19, 85, 85, 85, 85]':
                                            result = u'编程-ECUReset-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-ECUReset-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 1:
                                    if Data == 'Data=[3, 127, 20, 34, 85, 85, 85, 85]':
                                        result = u'编程-清除HUD诊断信息-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'编程-清除HUD诊断信息-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 2:
                                    if Data == 'Data=[3, 127, 25, 34, 85, 85, 85, 85]':
                                        result = u'编程-读取DTC数量-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'编程-读取DTC数量-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 3:
                                    if Action == 0:
                                        if Data:# == 'Data=[6, 103, 1, 0, 17, 34, 51, 85]':
                                            result = u'编程-安全访问，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-安全访问，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 39, 18, 85, 85, 85, 85]':
                                            result = u'编程-安全访问-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-安全访问-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 39, 19, 85, 85, 85, 85]':
                                            result = u'编程-安全访问-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-安全访问-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 4:
                                    if Action == 0:
                                        if Data == 'Data=[2, 104, 0, 85, 85, 85, 85, 85]':
                                            result = u'编程-通信控制-使能接收和发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-通信控制-使能接收和发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[2, 104, 1, 85, 85, 85, 85, 85]':
                                            result = u'编程-通信控制-使能接收且禁止发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-通信控制-使能接收且禁止发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[2, 104, 2, 85, 85, 85, 85, 85]':
                                            result = u'编程-通信控制-禁止接收且使能发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-通信控制-禁止接收且使能发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 3:
                                        if Data == 'Data=[2, 104, 3, 85, 85, 85, 85, 85]':
                                            result = u'编程-通信控制-禁止接收且禁止发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-通信控制-禁止接收且禁止发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 4:
                                        if Data == 'Data=[3, 127, 40, 18, 85, 85, 85, 85]':
                                            result = u'编程-通信控制-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-通信控制-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 5:
                                        if Data == 'Data=[3, 127, 40, 19, 85, 85, 85, 85]':
                                            result = u'编程-通信控制-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-通信控制-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 40, 49, 85, 85, 85, 85]':
                                            result = u'编程-通信控制-请求超出范围，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-通信控制-请求超出范围，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 5:
                                    if Action == 0:
                                        if Data == 'Data=[2, 126, 0, 85, 85, 85, 85, 85]':
                                            result = u'编程-诊断设备在线，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-诊断设备在线，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 62, 18, 85, 85, 85, 85]':
                                            result = u'编程-诊断设备在线-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-诊断设备在线-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 62, 19, 85, 85, 85, 85]':
                                            result = u'编程-诊断设备在线-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-诊断设备在线-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 6:
                                    if Action == 0:
                                        if Data == 'Data=[2, 197, 1, 85, 85, 85, 85, 85]':
                                            result = u'编程-打开DTC设置，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-打开DTC设置，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[2, 197, 2, 85, 85, 85, 85, 85]':
                                            result = u'编程-关闭DTC设置，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-关闭DTC设置，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 133, 18, 85, 85, 85, 85]':
                                            result = u'编程-DTC设置-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-DTC设置-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 133, 19, 85, 85, 85, 85]':
                                            result = u'编程-DTC设置-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'编程-DTC设置-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                        else:
                            result = u'编程切换编程，系统响应错误'
                            self.Recv_signal.emit(result)
                            BadMonkey += 1
                            self.BadMonkey_signal.emit(BadMonkey)
                    else:
                        result = u'系统响应帧ID不对'
                        self.Recv_signal.emit(result)
                        BadMonkey += 1
                        self.BadMonkey_signal.emit(BadMonkey)
                if ModelFlag == 2:  # can't cut from program to extend
                    frame.data = [0x02, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                    self.Sender_signal.emit(count, 1, str(frame))
                    dev.send(frame)
                    Mess = str(dev.recv())
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[3, 127, 16, 34, 85, 85, 85, 85]':
                            result = u'编程切换扩展，条件未满足，系统响应正确'
                            self.Recv_signal.emit(result)
                        else:
                            result = u'编程切换扩展，条件未满足，系统响应错误'
                            self.Recv_signal.emit(result)
                            BadMonkey += 1
                            self.BadMonkey_signal.emit(BadMonkey)
                    else:
                        result = u'系统响应帧ID不对'
                        self.Recv_signal.emit(result)
                        BadMonkey += 1
                        self.BadMonkey_signal.emit(BadMonkey)
            else:
                if ModelFlag == 0:
                    frame.data = [0x02, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                    self.Sender_signal.emit(count, 1, str(frame))
                    dev.send(frame)
                    Mess = str(dev.recv())
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[6, 80, 1, 0, 50, 1, 244, 85]':
                            result = u'扩展切换默认，系统响应正确'
                            self.Recv_signal.emit(result)
                            Flag = 0
                            if Response == 0:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x11, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 1:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x04, 0x14, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x04, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x05, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x14, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 2:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x03, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x03, 0x19, 0x03, 0x09, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x04, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x19, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00]
                            if Response == 3:
                                frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 4:
                                frame.data = [0x03, 0x28, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00]
                            if Response == 5:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 6:
                                frame.data = [0x02, 0x85, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                            self.Sender_signal.emit(count, 1, str(frame))
                            dev.send(frame)
                            Mess = str(dev.recv())
                            new = Mess.split('\n')
                            final = new[0] + new[1]
                            self.Recv_signal.emit(final)
                            Pattern_id = re.compile(r'ID=0x7A9,')
                            Match = Pattern_id.search(Mess)
                            if Match:
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Response == 0:
                                    if Action == 0:
                                        if Data == 'Data=[2, 81, 3, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-软件复位，系统响应正确'
                                            self.Recv_signal.emit(result)
                                            Flag = 0
                                            time.sleep(5)
                                        else:
                                            result = u'扩展切换默认-软件复位，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 17, 18, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-ECUReset-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-ECUReset-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 17, 19, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-ECUReset-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-ECUReset-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 1:
                                    if Action == 0:
                                        if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-清除HUD诊断信息，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-清除HUD诊断信息，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-清除所有组诊断信息，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-清除所有组诊断信息，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 20, 19, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-清除诊断-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-清除诊断-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 20, 49, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-清除诊断-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-清除诊断-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 2:
                                    if Action == 0:
                                        if Data == 'Data=[6, 89, 1, 9, 1, 0, 1, 85]':
                                            result = u'扩展切换默认-读取DTC数量，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-读取DTC数量，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 25, 18, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-读取DTC-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-读取DTC-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 25, 19, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-读取DTC-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-读取DTC-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 25, 49, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-读取DTC-请求超出范围，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-读取DTC-请求超出范围，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 5:
                                    if Action == 0:
                                        if Data == 'Data=[2, 126, 0, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-诊断设备在线，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-诊断设备在线，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 62, 18, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-诊断设备在线-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-诊断设备在线-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 62, 19, 85, 85, 85, 85]':
                                            result = u'扩展切换默认-诊断设备在线-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换默认-诊断设备在线-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 3:
                                    if Data == 'Data=[3, 127, 39, 34, 85, 85, 85, 85]':
                                        result = u'默认切换编程，安全访问-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'默认切换编程，安全访问-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 4:
                                    if Data == 'Data=[3, 127, 40, 34, 85, 85, 85, 85]':
                                        result = u'默认切换默认，通信控制-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'默认切换编程，通信控制-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 6:
                                    if Data == 'Data=[3, 127, 133, 34, 85, 85, 85, 85]':
                                        result = u'默认切换编程，控制DTC设置-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'默认切换编程，控制DTC设置-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                        else:
                            result = u'扩展切换默认，系统响应错误'
                            self.Recv_signal.emit(result)
                            BadMonkey += 1
                            self.BadMonkey_signal.emit(BadMonkey)
                    else:
                        result = u'系统响应帧ID不对'
                        self.Recv_signal.emit(result)
                        BadMonkey += 1
                        self.BadMonkey_signal.emit(BadMonkey)
                if ModelFlag == 1:
                    frame.data = [0x02, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                    self.Sender_signal.emit(count, 1, str(frame))
                    dev.send(frame)
                    Mess = str(dev.recv())
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[6, 80, 2, 0, 50, 1, 244, 85]':
                            result = u'扩展切换编程，系统响应正确'
                            self.Recv_signal.emit(result)
                            Flag = 1
                            if Response == 0:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x11, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 1:
                                frame.data = [0x04, 0x14, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 2:
                                frame.data = [0x03, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                            if Response == 3:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x27, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 4:
                                Action = random.randint(0, 6)
                                if Action == 0:
                                    frame.data = [0x03, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x03, 0x28, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x03, 0x28, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 3:
                                    frame.data = [0x03, 0x28, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 4:
                                    frame.data = [0x03, 0x28, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 5:
                                    frame.data = [0x04, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x28, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00]
                            if Response == 5:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 6:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x02, 0x85, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x02, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                            self.Sender_signal.emit(count, 1, str(frame))
                            dev.send(frame)
                            Mess = str(dev.recv())
                            new = Mess.split('\n')
                            final = new[0] + new[1]
                            self.Recv_signal.emit(final)
                            Pattern_id = re.compile(r'ID=0x7A9,')
                            Match = Pattern_id.search(Mess)
                            if Match:
                                Pattern_Data = re.compile(r'Data=.+')
                                DataGroup = Pattern_Data.search(Mess)
                                Data = DataGroup.group()
                                if Response == 0:
                                    if Action == 0:
                                        if Data == 'Data=[2, 81, 3, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-软件复位，系统响应正确'
                                            self.Recv_signal.emit(result)
                                            Flag = 0
                                            time.sleep(5)
                                        else:
                                            result = u'扩展切换编程-软件复位，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 17, 18, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-ECUReset-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-ECUReset-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 17, 19, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-ECUReset-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-ECUReset-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 1:
                                    if Data == 'Data=[3, 127, 20, 34, 85, 85, 85, 85]':
                                        result = u'扩展切换编程-清除HUD诊断信息-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展切换编程-清除HUD诊断信息-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 2:
                                    if Data == 'Data=[3, 127, 25, 34, 85, 85, 85, 85]':
                                        result = u'扩展切换编程-读取DTC数量-条件未满足，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展切换编程-读取DTC数量-条件未满足，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 3:
                                    if Action == 0:
                                        if Data:# == 'Data=[6, 103, 1, 0, 17, 34, 51, 85]':
                                            result = u'扩展切换编程-安全访问，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-安全访问，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 39, 18, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-安全访问-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-安全访问-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 39, 19, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-安全访问-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-安全访问-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 4:
                                    if Action == 0:
                                        if Data == 'Data=[2, 104, 0, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-通信控制-使能接收和发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-通信控制-使能接收和发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[2, 104, 1, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-通信控制-使能接收且禁止发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-通信控制-使能接收且禁止发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[2, 104, 2, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-通信控制-禁止接收且使能发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-通信控制-禁止接收且使能发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 3:
                                        if Data == 'Data=[2, 104, 3, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-通信控制-禁止接收且禁止发送，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-通信控制-禁止接收且禁止发送，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 4:
                                        if Data == 'Data=[3, 127, 40, 18, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-通信控制-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-通信控制-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 5:
                                        if Data == 'Data=[3, 127, 40, 19, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-通信控制-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-通信控制-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 40, 49, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-通信控制-请求超出范围，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-通信控制-请求超出范围，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 5:
                                    if Action == 0:
                                        if Data == 'Data=[2, 126, 0, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-诊断设备在线，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-诊断设备在线，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[3, 127, 62, 18, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-诊断设备在线-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-诊断设备在线-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 62, 19, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-诊断设备在线-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-诊断设备在线-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                if Response == 6:
                                    if Action == 0:
                                        if Data == 'Data=[2, 197, 1, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-打开DTC设置，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-打开DTC设置，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 1:
                                        if Data == 'Data=[2, 197, 2, 85, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-关闭DTC设置，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-关闭DTC设置，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    elif Action == 2:
                                        if Data == 'Data=[3, 127, 133, 18, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-DTC设置-子功能不支持，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-DTC设置-子功能不支持，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                                    else:
                                        if Data == 'Data=[3, 127, 133, 19, 85, 85, 85, 85]':
                                            result = u'扩展切换编程-DTC设置-报文长度错误，系统响应正确'
                                            self.Recv_signal.emit(result)
                                        else:
                                            result = u'扩展切换编程-DTC设置-报文长度错误，系统响应错误'
                                            self.Recv_signal.emit(result)
                                            BadMonkey += 1
                                            self.BadMonkey_signal.emit(BadMonkey)
                        else:
                            result = u'扩展切换编程，系统响应错误'
                            self.Recv_signal.emit(result)
                            BadMonkey += 1
                            self.BadMonkey_signal.emit(BadMonkey)
                    else:
                        result = u'系统响应帧ID不对'
                        self.Recv_signal.emit(result)
                        BadMonkey += 1
                        self.BadMonkey_signal.emit(BadMonkey)
                if ModelFlag == 2:
                    frame.data = [0x02, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                    self.Sender_signal.emit(count, 1, str(frame))
                    dev.send(frame)
                    Mess = str(dev.recv())
                    new = Mess.split('\n')
                    final = new[0] + new[1]
                    self.Recv_signal.emit(final)
                    Pattern_id = re.compile(r'ID=0x7A9,')
                    Match = Pattern_id.search(Mess)
                    if Match:
                        Pattern_Data = re.compile(r'Data=.+')
                        DataGroup = Pattern_Data.search(Mess)
                        Data = DataGroup.group()
                        if Data == 'Data=[6, 80, 3, 0, 50, 1, 244, 85]':
                            result = u'扩展切换扩展，系统响应正确'
                            self.Recv_signal.emit(result)
                            if Response == 0:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x11, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x11, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 1:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x04, 0x14, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x04, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x05, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x14, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 2:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x03, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x03, 0x19, 0x03, 0x09, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x04, 0x19, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x19, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00]
                            if Response == 3:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x27, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x04, 0x27, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 4:
                                Action = random.randint(0, 6)
                                if Action == 0:
                                    frame.data = [0x03, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x03, 0x28, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x03, 0x28, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 3:
                                    frame.data = [0x03, 0x28, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 4:
                                    frame.data = [0x03, 0x28, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 5:
                                    frame.data = [0x04, 0x28, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x28, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00]
                            if Response == 5:
                                Action = random.randint(0, 2)
                                if Action == 0:
                                    frame.data = [0x02, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x3E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                            if Response == 6:
                                Action = random.randint(0, 3)
                                if Action == 0:
                                    frame.data = [0x02, 0x85, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 1:
                                    frame.data = [0x02, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                                elif Action == 2:
                                    frame.data = [0x02, 0x85, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00]
                                else:
                                    frame.data = [0x03, 0x85, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00]
                        self.Sender_signal.emit(count, 1, str(frame))
                        dev.send(frame)
                        Mess = str(dev.recv())
                        new = Mess.split('\n')
                        final = new[0] + new[1]
                        self.Recv_signal.emit(final)
                        Pattern_id = re.compile(r'ID=0x7A9,')
                        Match = Pattern_id.search(Mess)
                        if Match:
                            Pattern_Data = re.compile(r'Data=.+')
                            DataGroup = Pattern_Data.search(Mess)
                            Data = DataGroup.group()
                            if Response == 0:
                                if Action == 0:
                                    if Data == 'Data=[2, 81, 3, 85, 85, 85, 85, 85]':
                                        result = u'扩展-软件复位，系统响应正确'
                                        self.Recv_signal.emit(result)
                                        Flag = 0
                                        time.sleep(5)
                                    else:
                                        result = u'扩展-软件复位，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 1:
                                    if Data == 'Data=[3, 127, 17, 18, 85, 85, 85, 85]':
                                        result = u'扩展-ECUReset-子功能不支持，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-ECUReset-子功能不支持，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                else:
                                    if Data == 'Data=[3, 127, 17, 19, 85, 85, 85, 85]':
                                        result = u'扩展-ECUReset-报文长度错误，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-ECUReset-报文长度错误，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                            if Response == 1:
                                if Action == 0:
                                    if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                                        result = u'扩展-清除HUD诊断信息，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-清除HUD诊断信息，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 1:
                                    if Data == 'Data=[1, 84, 85, 85, 85, 85, 85, 85]':
                                        result = u'扩展-清除所有组诊断信息，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-清除所有组诊断信息，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 2:
                                    if Data == 'Data=[3, 127, 20, 19, 85, 85, 85, 85]':
                                        result = u'扩展-清除诊断信息-报文长度错误，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-清除诊断信息-报文长度错误，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                else:
                                    if Data == 'Data=[3, 127, 20, 49, 85, 85, 85, 85]':
                                        result = u'扩展-清除诊断信息-请求超出范围，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-清除诊断信息-请求超出范围，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                            if Response == 2:
                                if Action == 0:
                                    if Data == 'Data=[6, 89, 1, 9, 1, 0, 1, 85]':
                                        result = u'扩展-读取DTC数量，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-读取DTC数量，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 1:
                                    if Data == 'Data=[3, 127, 25, 18, 85, 85, 85, 85]':
                                        result = u'扩展-读取DTC-子功能不支持，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-读取DTC-子功能不支持，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 2:
                                    if Data == 'Data=[3, 127, 25, 19, 85, 85, 85, 85]':
                                        result = u'扩展-读取DTC-报文长度错误，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-读取DTC-报文长度错误，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                else:
                                    if Data == 'Data=[3, 127, 25, 49, 85, 85, 85, 85]':
                                        result = u'扩展-读取DTC-请求超出范围，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-读取DTC-请求超出范围，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                            if Response == 3:
                                if Action == 0:
                                    if Data:# == 'Data=[6, 103, 1, 0, 17, 34, 51, 85]':
                                        result = u'扩展-安全访问，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-安全访问，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 1:
                                    if Data == 'Data=[3, 127, 39, 18, 85, 85, 85, 85]':
                                        result = u'扩展-安全访问-子功能不支持，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-安全访问-子功能不支持，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                else:
                                    if Data == 'Data=[3, 127, 39, 19, 85, 85, 85, 85]':
                                        result = u'扩展-安全访问-报文长度错误，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-安全访问-报文长度错误，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                            if Response == 4:
                                if Action == 0:
                                    if Data == 'Data=[2, 104, 0, 85, 85, 85, 85, 85]':
                                        result = u'扩展-通信控制-使能接收和发送，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-通信控制-使能接收和发送，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 1:
                                    if Data == 'Data=[2, 104, 1, 85, 85, 85, 85, 85]':
                                        result = u'扩展-通信控制-使能接收且禁止发送，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-通信控制-使能接收且禁止发送，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 2:
                                    if Data == 'Data=[2, 104, 2, 85, 85, 85, 85, 85]':
                                        result = u'扩展-通信控制-禁止接收且使能发送，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-通信控制-禁止接收且使能发送，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 3:
                                    if Data == 'Data=[2, 104, 3, 85, 85, 85, 85, 85]':
                                        result = u'扩展-通信控制-禁止接收且禁止发送，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-通信控制-禁止接收且禁止发送，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 4:
                                    if Data == 'Data=[3, 127, 40, 18, 85, 85, 85, 85]':
                                        result = u'扩展-通信控制-子功能不支持，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-通信控制-子功能不支持，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 5:
                                    if Data == 'Data=[3, 127, 40, 19, 85, 85, 85, 85]':
                                        result = u'扩展-通信控制-报文长度错误，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-通信控制-报文长度错误，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                else:
                                    if Data == 'Data=[3, 127, 40, 49, 85, 85, 85, 85]':
                                        result = u'扩展-通信控制-请求超出范围，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-通信控制-请求超出范围，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                            if Response == 5:
                                if Action == 0:
                                    if Data == 'Data=[2, 126, 0, 85, 85, 85, 85, 85]':
                                        result = u'扩展-诊断设备在线，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-诊断设备在线，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 1:
                                    if Data == 'Data=[3, 127, 62, 18, 85, 85, 85, 85]':
                                        result = u'扩展-诊断设备在线-子功能不支持，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-诊断设备在线-子功能不支持，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                else:
                                    if Data == 'Data=[3, 127, 62, 19, 85, 85, 85, 85]':
                                        result = u'扩展-诊断设备在线-报文长度错误，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-诊断设备在线-报文长度错误，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                            if Response == 6:
                                if Action == 0:
                                    if Data == 'Data=[2, 197, 1, 85, 85, 85, 85, 85]':
                                        result = u'扩展-打开DTC设置，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-打开DTC设置，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 1:
                                    if Data == 'Data=[2, 197, 2, 85, 85, 85, 85, 85]':
                                        result = u'扩展-关闭DTC设置，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-关闭DTC设置，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                elif Action == 2:
                                    if Data == 'Data=[3, 127, 133, 18, 85, 85, 85, 85]':
                                        result = u'扩展-DTC设置-子功能不支持，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-DTC设置-子功能不支持，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                                else:
                                    if Data == 'Data=[3, 127, 133, 19, 85, 85, 85, 85]':
                                        result = u'扩展-DTC设置-报文长度错误，系统响应正确'
                                        self.Recv_signal.emit(result)
                                    else:
                                        result = u'扩展-DTC设置-报文长度错误，系统响应错误'
                                        self.Recv_signal.emit(result)
                                        BadMonkey += 1
                                        self.BadMonkey_signal.emit(BadMonkey)
                        else:
                            result = u'扩展切换扩展，系统响应错误'
                            self.Recv_signal.emit(result)
                            BadMonkey += 1
                            self.BadMonkey_signal.emit(BadMonkey)
                    else:
                        result = u'系统响应帧ID不对'
                        self.Recv_signal.emit(result)
                        BadMonkey += 1
                        self.BadMonkey_signal.emit(BadMonkey)


class ARMonkey(QtCore.QThread):
    Sender_signal = QtCore.pyqtSignal(int, int, str)
    ARMCount = QtCore.pyqtSignal(int)
    ARMType = QtCore.pyqtSignal(str)

    def __init__(self, parent=None):
        super(self.__class__, self).__init__(parent)

    def __del__(self):
        self.wait()

    def run(self):
        TypeResult = ''
        TypeList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
                    28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]
        DataList = []
        MargeList = []
        # count=random.randint(2,40)#故障个数,最少2个，单个功能测试已经完成
        count = 5
        self.ARMCount.emit(count)
        ArmList = random.sample(TypeList, count)
        for i in ArmList:
            Result, data = self.ArmPatch(i)
            TypeResult += Result
            DataList.append(data)
        self.ARMType.emit(TypeResult)
        # print(DataList)
        for i in range(0, count):
            try:
                SourceList = DataList[i]
                # print(SourceList)
                # print(type(SourceList))
                SourceSplitList = SourceList.split(' ')
                # print(DataList[i][0:4])
                for j in range(i + 1, count):
                    TargetList = DataList[j]
                    TargetSplitList = TargetList.split(' ')
                    if SourceList[0:4] == TargetList[0:4]:  # ID相同
                        # print(SourceList[0:4])
                        for loop in range(1, 9):
                            # print(SourceSplitList[loop])
                            # print(TargetSplitList[loop])
                            if SourceSplitList[loop] != TargetSplitList[loop]:
                                # print(loop)
                                SourceStr = int('0x' + SourceSplitList[loop], 16)
                                TargetStr = int('0x' + TargetSplitList[loop], 16)
                                MargeData = hex(SourceStr + TargetStr)
                                print(MargeData.lstrip('0x'))
                                # print(SourceList[loop*3+2:loop*3+4])
                                SourceList = SourceList[0:loop * 3 + 2] + MargeData.lstrip('0x') + SourceList[
                                                                                                   loop * 3 + 4:28]
                                # SourceList[loop*3+2:loop*3+4]+=MargeData.lstrip('0x')
                                # print(SourceList)
                            else:
                                SourceList = SourceList[0:loop * 3 + 2] + SourceSplitList[loop] + SourceList[
                                                                                                  loop * 3 + 4:28]
                                # SourceList[loop*3+2:loop*3+4]+=SourceSplitList[loop]
                        # print(SourceList)
                        DataList.remove(TargetList)
                        # print(DataList)
                        # count=count-1
                    DataList[i] = SourceList
            except:
                pass
        # print(DataList)

    def ArmPatch(self, type):
        ArmResult = ''
        if type == 1:
            ArmResult = u'动力系统故障 '
            data = '021A 00 00 00 04 00 00 00 00'
        if type == 2:
            ArmResult = u'PEPS钥匙遗忘在车内 '
            data = '024C 01 00 00 00 00 00 00 00'
        if type == 3:
            ArmResult = u'PEPS钥匙遗不在车内 '
            data = '024C 08 00 00 00 00 00 00 00'
        if type == 4:
            ArmResult = u'动力电池温度高 '
            data = '020C 00 04 00 00 00 00 00 00'
        if type == 5:
            ArmResult = u'动力电池故障 '
            data = '020C 01 00 00 00 00 00 00 00'
        if type == 6:
            ArmResult = u'电池电流过高故障 '
            data = '020C 00 40 00 00 00 00 00 00'
        if type == 7:
            ArmResult = u'充电电流过大故障 '
            data = '020C 00 00 00 00 00 04 00 00'
        if type == 8:
            ArmResult = u'放电电流过大故障 '
            data = '020C 00 00 00 00 00 10 00 00'
        if type == 9:
            ArmResult = u'EPB故障 '
            data = '0150 01 00 00 00 00 00 00 00'
        if type == 10:
            ArmResult = u'电池组最低单体电压报警 '
            data = '020C 10 00 00 00 00 00 00 00'
        if type == 11:
            ArmResult = u'绝缘故障指示 '
            data = '020C 00 00 00 00 00 01 00 00'
        if type == 12:
            ArmResult = u'电机故障 '
            data = '0242 00 00 00 00 10 00 00 00'
        if type == 13:
            ArmResult = u'驱动性能受限 '
            data = '021A 00 00 00 00 00 10 00 00'
        if type == 14:
            ArmResult = u'右前车门打开 '
            data = '0152 01 00 00 00 00 00 00 00'
        if type == 15:
            ArmResult = u'左前车门打开 '
            data = '0152 02 00 00 00 00 00 00 00'
        if type == 16:
            ArmResult = u'左后车门打开 '
            data = '0152 00 40 00 00 00 00 00 00'
        if type == 17:
            ArmResult = u'右后车门打开 '
            data = '0152 00 80 00 00 00 00 00 00'
        if type == 18:
            ArmResult = u'所有车门打开 '
            data = '0152 03 C0 00 00 00 00 00 00'
        if type == 19:
            ArmResult = u'右后轮胎压故障 '
            data = '0262 00 00 00 00 01 00 00 00'
        if type == 20:
            ArmResult = u'左后轮胎压故障 '
            data = '0262 00 00 00 00 04 00 00 00'
        if type == 21:
            ArmResult = u'右前轮胎压故障 '
            data = '0262 00 00 00 00 10 00 00 00'
        if type == 22:
            ArmResult = u'左前轮胎压故障 '
            data = '0262 00 00 00 00 40 00 00 00'
        if type == 23:
            ArmResult = u'所有胎压故障 '
            data = '0262 00 00 00 00 55 00 00 00'
        if type == 24:
            ArmResult = u'右后胎温故障 '
            data = '0264 00 00 00 00 10 00 00 00'
        if type == 25:
            ArmResult = u'左后胎温故障 '
            data = '0264 00 00 00 00 20 00 00 00'
        if type == 26:
            ArmResult = u'右前胎温故障 '
            data = '0264 00 00 00 00 40 00 00 00'
        if type == 27:
            ArmResult = u'左前胎温故障 '
            data = '0264 00 00 00 00 80 00 00 00'
        if type == 28:
            ArmResult = u'所有胎温故障 '
            data = '0264 00 00 00 00 F0 00 00 00'
        if type == 29:
            ArmResult = u'左前胎压 '
            data = '0262 FE 00 00 00 00 00 00 00'
        if type == 30:
            ArmResult = u'右前胎压 '
            data = '0262 00 FE 00 00 00 00 00 00'
        if type == 31:
            ArmResult = u'左后胎压 '
            data = '0262 00 00 FE 00 00 00 00 00'
        if type == 32:
            ArmResult = u'右后胎压 '
            data = '0262 00 00 00 FE 00 00 00 00'
        if type == 33:
            ArmResult = u'左前胎温 '
            data = '0264 FE 00 00 00 00 00 00 00'
        if type == 34:
            ArmResult = u'右前胎温 '
            data = '0264 00 FE 00 00 00 00 00 00'
        if type == 35:
            ArmResult = u'左后胎压 '
            data = '0264 00 00 FE 00 00 00 00 00'
        if type == 36:
            ArmResult = u'右后胎压 '
            data = '0264 00 00 00 FE 00 00 00 00'
        if type == 37:
            ArmResult = u'真空助力泵报警 '
            data = '021A 00 00 00 00 40 00 00 00'
        if type == 38:
            ArmResult = u'快速漏气报警提示-车身闪烁 '
            data = '0265 00 01 00 00 00 00 00 00'
        if type == 39:
            ArmResult = u'TPMS系统故障-常亮 '
            data = '0265 01 00 00 00 00 00 00 00'
        if type == 40:
            ArmResult = u'TPMS传感器电量低-闪烁 '
            data = '0265 10 00 00 00 00 00 00 00'
        return ArmResult, data


def main():
    reload(sys)
    sys.setdefaultencoding('UTF-8')
    app = QtGui.QApplication(sys.argv)
    mycode = locale.getpreferredencoding()
    code = QtCore.QTextCodec.codecForName(mycode)
    QtCore.QTextCodec.setCodecForLocale(code)
    QtCore.QTextCodec.setCodecForTr(code)
    QtCore.QTextCodec.setCodecForCStrings(code)
    w = MyWindow()
    w.show()
    sys.exit(app.exec_())


if __name__ == "__main__":
    main()
